combine a field from a sub stack

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
mister
Posts: 39
Joined: Thu Nov 27, 2014 9:03 pm

combine a field from a sub stack

Post by mister » Fri Sep 29, 2017 8:41 pm

It's been a many, many months since I've worked with livecode due to work etc. So i'm back to beginner status and i can't believe i have to ask this question.

Anyway, I'm trying to combine 2 fields with this save command. it's a knockoff of the notes app ( 8.0 +) where the highlited line of the notes list takes you to the individual note There is already text in both fields. They are both forms that when merged need additonal text/information added. The fields merege fine and i can add new text to the top of the combined field. When I add text to the second part (additonalInfo) of the COMBINED FORM, resave and then reopen them, the (additionalInfo)field from the substack is duplicated at the bottom of the form. Wouldn't the "else" statment know that the fields are alreay combided?

command saveNote
-- Declare any local variables
local tFilePath
-- Check that there is text in the note
put noteFilename() into tFilePath
if field "noteText" is not empty then
if fld "additionalInfo" of stack "refSub" is not in fld "noteText" then
put cr & fld "additionalInfo" of stack "refSub" after fld "noteText"
end if
else
end if

put fld "noteText" into url ("file:" & tFilePath)
end saveNote

using 8.1.3

Thanks,
Larry

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: combine a field from a sub stack

Post by Klaus » Fri Sep 29, 2017 8:57 pm

Hi Larry,

not sure I understand your problem?

But here some hints for speed and effectiveness:

Code: Select all

command saveNote
   -- Declare any local variables 
   local tFilePath 
   -- Check that there is text in the note
   put noteFilename() into tFilePath
      
   ## Save lots of unnecdessary END IFs etc. by exiting whenever possible, and no ELSE neccessary if there is in fact no ELSE case :-)
   ## In this case here:
   if field "noteText" = empty then
      exit saveNote
   end if
   
   #    if field "noteText" is not empty then
   #       if fld "additionalInfo" of stack "refSub" is not in fld "noteText" then
   #          put cr & fld "additionalInfo" of stack "refSub" after fld "noteText"
   #       end if
   #    else
   #    end if

   ## Accessing fields more than once is ineffective, better put the content
   ## into variables first and write bakc into field at the latest possible point...
   put fld "additionalInfo" of stack "refSub" into tAddInfo
   put fld "noteText" into tNt
  
  ## ... which is here: 
   if tAddInfo contains tNt then
      put cr & tAddInfo after fld "noteText"
   end if
     
   put fld "noteText" into url ("file:" & tFilePath)
end saveNote
Hint: After pasting your script here, select it and apply the "Code" code by clicking the,
well, "Code" button at the top of this field :D

Best

Klaus

mister
Posts: 39
Joined: Thu Nov 27, 2014 9:03 pm

Re: combine a field from a sub stack

Post by mister » Mon Oct 02, 2017 7:17 pm

Klaus,

Obviously, i like to over complicate things, plus I left out some vital information. First of all, this should probably be in a database. I'm just trying to avoid doing that or just map it out beforehand. Field "noteText" is a question and answer form that will eventually come from a website and is placed in a referrals folder. Field "additionalInfo" is also a form on a desktop app that requires a phone call to gather "sensitive/more information from the potential client than the website form provides and gives us an opportunity to contact the client by phone. Then the two are combined into one file in the referrals folder.

After seeing your suggestion, i realized that "noteText" will never be empty and came up with this that works so far.

Code: Select all

command saveNote
   -- Declare any local variables 
   local tFilePath, tAdditionalInfo
   -- Check that there is text in the note
   put noteFilename() into tFilePath
   
   if field "noteText" is not empty then
      put fld "additionalInfo" of stack "refSub" into tAdditionalInfo 
   end if
   
   if the number of lines in fld "noteText" <=  22  then
      -- if tFilePath contains noteFileName then
      put cr & tAdditionalInfo after fld "noteText"
   end if
   put fld "noteText" into url ("file:" & tFilePath)
   visual effect "push" right fast
   go to card "refList"
end saveNote
Thanks for your help!
Larry

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”