Put IT into more than one field

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

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Put IT into more than one field

Post by CAsba » Wed Oct 19, 2022 12:42 pm

Hi,
Is it possible to put IT into more than one field ? I just tried

if field Compnamex = "." then

ask "Enter the name of the business"
put it into field Compnamex
put it into field Compnamex_inv
if field Compnamex is empty then
ask "Enter the name of the business"
put it into field Compnamex
end if
else
exit mouseup
end if

I got an error on the second 'put it'.

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Put IT into more than one field

Post by Klaus » Wed Oct 19, 2022 12:50 pm

Try this:

Code: Select all

on mouseup
   
   ## QUOTES QUOTES QUOTES!
   if field "Compnamex" = "." then   
      ask "Enter the name of the business"
      
      ## IT will change when you LEAST exspect it, so always put IT into a variable immediately!
      put it into tAnswer
      
      ## User clicked CANCEL
      if the result = "cancel" then
         exit mouseup
      end if
      
      ## QUOTES QUOTES QUOTES!
      put tAnswer into field "Compnamex"
      put tAnswer into field "Compnamex_inv"
      
      ## Done:
   end if
   
   ## Since this is INSIDE of the first IF THEN structure, this does not make sense, that fleld is NEVER empty
   ## Maybe you want to put this OUTSIDE of the first IF THEN?
   #      if field "Compnamex" is empty then
   #         ask "Enter the name of the business"
   #         put it into field Compnamex
   #      end if
   #   else
   #      exit mouseup
   # end if
end mouseup
QUOTES and CODE tags, remember? 8)

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: Put IT into more than one field

Post by CAsba » Wed Oct 19, 2022 1:49 pm

Hi Klaus,
Got that. Many thanks.
I should explain that the field does become empty if the user were to click OK or Cancel without entering any text. The idea here is to FORCE the user, only on this occasion, to enter a business name. I envisage the programme to be either downloaded or supplied on a USB stick, and it's my strategy to ensure a business name has been entered, and cannot be edited, so that if the prog is copied it will be useless as a new business name will not be able to be entered. hope this makes sense.

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Put IT into more than one field

Post by Klaus » Wed Oct 19, 2022 2:01 pm

AHA, get it.

However I NEVER used IT if empty and it does not make sense GUI-wise... 8)

Know what I mean?
If I click CANCEL or OK without entering any text, no user will exspect that something will happen like emptying a field!

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: Put IT into more than one field

Post by CAsba » Wed Oct 19, 2022 2:44 pm

Hi Klaus,
I just tried all the commented lines below without success. (The first two lines that referred to the same card worked ok).
" ask "Enter the name of the business"
put it into tAnswer
put tAnswer into field "Compnamex"
put tAnswer into field "Indequal1"
#put tAnswer into field "Compnamex_inv" in card
#put the text of field "compnamex" of this cd into field "compnamex_inv" of cd "DoxInv"
#put the text of field tAnswer of this cd into field "compnamex_inv" of cd "DoxInv"
#put tAnswer into field "compnamex_inv" of cd "DoxInv"
# put tAnswer into field "compnamex_inv" of cd id 1002
#put the text of fld "compnamex" of cd "casba" of stack "casba accounts" of stack "path/to/stack/on_disk.livecode"into field "compnamex_inv" of cd "doxinv"
#put the text of fld "compnamex" of cd "casba" of stack "casba accounts" into field "compnamex_inv" of cd "doxinv"
"
Any ideas ?

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Put IT into more than one field

Post by Klaus » Wed Oct 19, 2022 2:53 pm

These uncommented lines should definitively work:

Code: Select all

...
ask "Enter the name of the business"
put it into tAnswer
put tAnswer into field "Compnamex"
put tAnswer into field "Indequal1"
## put tAnswer into field "Compnamex_inv" in card
## leave out ... in card
put tAnswer into field "Compnamex_inv"
   
## ...of this cd is not neccessary, since LC always thinks we mean objects on the current card
put the text of field "compnamex" of this cd into field "compnamex_inv" of cd "DoxInv"
put the text of field tAnswer of this cd into field "compnamex_inv" of cd "DoxInv"
put tAnswer into field "compnamex_inv" of cd "DoxInv"
put tAnswer into field "compnamex_inv" of cd id 1002
## If all of these cards and fields are really present in your stack, then this should work!

## Target stack is missing in these two lines:
#put the text of fld "compnamex" of cd "casba" of stack "casba accounts" of stack "path/to/stack/on_disk.livecode"into field "compnamex_inv" of cd "doxinv"
#put the text of fld "compnamex" of cd "casba" of stack "casba accounts" into field "compnamex_inv" of cd "doxinv"
...
Hint:
You can use some more abbreviations:
fld = field
btn = button

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: Put IT into more than one field

Post by stam » Wed Oct 19, 2022 2:57 pm

CAsba wrote:
Wed Oct 19, 2022 2:44 pm
Any ideas ?
Not sure what's going on there, but what i would do if this don't appear to be working is set a breakpoint in the handler and examine what value is assigned to tAnswer first of all.

Other than that it should work. I note you have some incorrect syntax in your commented lines (eg in some of your commented lines you're treating the variable as a field, which is wrong) - the correct syntax is

Code: Select all

put <variable> into field <fieldName> [of this card | of card <cardName> [of stack <stackName>]] 
# OR
set the text of field <fieldName> [of this card | of card <cardName> [of stack <stackName>]]  to <variable>

if the field is on the same card you're on, you do not need to specify card - this is useful if you have multiple cards that have a field with the same name and you want to run the operation on the card without knowing the specific card. Optionally you can specify 'of this card' to ensure this card is acted on (and not for example a field with the same name that's in a group on the card). If the field you want to modify is on a different card you need to specify card name and optionally stack name, if the card is in a different stack.

However as mentioned, if things don't appear to be working, it's not usually the assignment operation that is wrong, it's that the variable you're assigning doesn't have the expected value - so setting a breakpoint in the script editor and examining the content of the variable usually locates the issue.

Hope that helps
S.

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: Put IT into more than one field

Post by CAsba » Wed Oct 19, 2022 3:09 pm

Hi Klaus,
Just to give you the full explanation of my styrategy, I enclose the whole script...

Code: Select all

on mouseUp pMouseButton
   if field Compnamex = "." then
      #lock screen
      ask "Enter the name of the business"
      put it into tAnswer
      put tAnswer into field "Compnamex"
      put tAnswer into field "Indequal1"
      #put tAnswer into field "Compnamex_inv" in card
      #put the text of field "compnamex" of this cd into field "compnamex_inv" of cd "DoxInv"
      #put the text of field tAnswer of this cd into field "compnamex_inv" of cd "DoxInv"
      #put tAnswer into field "compnamex_inv" of cd "DoxInv"
      put tAnswer into field "compnamex_inv" of cd id 1002
      #put the text of fld "compnamex" of cd "casba" of stack "casba accounts" of stack "path/to/stack/on_disk.livecode"into field "compnamex_inv" of cd "doxinv"
      #put the text of fld "compnamex" of cd "casba" of stack "casba accounts" into field "compnamex_inv" of cd "doxinv"
      
      if field Compnamex is empty then  ##user has clicked ok or cancel with no entry
         ask "Enter the name of the business"
         put it into field Compnamex
      end if
   else
      exit mouseup
   end if
   --
   if field Compnamex is empty then ##user has clicked ok or cancel with no entry
      ask "Enter the name of the business"
      
      put it into tAnswer
      put tAnswer into field "Compnamex"
      put tAnswer into field "Compnamex_inv"
      if field Compnamex is empty then  ##user has clicked ok or cancel with no entry
         ask "Enter the name of the business"
         put it into tAnswer
         put tAnswer into field "Compnamex"
         put tAnswer into field "Compnamex_inv"
      end if
   else
      exit mouseup
   end if
   --
   if field Compnamex is empty then  ##user has clicked ok or cancel with no entry
      ask "Enter the name of the business"
      put it into tAnswer
      put tAnswer into field "Compnamex"
      put tAnswer into field "Compnamex_inv"
      if field Compnamex is empty then  ##user has clicked ok or cancel with no entry
         ask "Last chance. Enter the name of the business."
         put it into tAnswer
         put tAnswer into field "Compnamex"
         put tAnswer into field "Compnamex_inv"
         
         if field Compnamex is empty then  ##user has clicked ok or cancel with no entry
            put "xyz" into field Compnamex  ##programme is no longer usable or copiable. Note, prior to running the prog, ther user is advised/warned                                        ##that if the user is not prepared to enter a business name, the prog should NOT be run.
            save stack "CAsba accounts" with newest format
            exit mouseup
         end if
      end if
   end if
   save stack "CAsba accounts" with newest format
end mouseup

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: Put IT into more than one field

Post by CAsba » Wed Oct 19, 2022 3:55 pm

Hi Klaus,
None of them worked, to compnamex_inv.

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Put IT into more than one field

Post by Klaus » Wed Oct 19, 2022 4:50 pm

See what the CODE tags -> <> do?
I just added them to your posting.

Looking at the script this should work!
Send me the stack if you like and I will take look: klaus AT major.k.de

However if the user clicked CANCEL or entered nothing I would just don't do anything, but stay on that card and do nothing.
If the user does not want to participate, well, his/her problem.

And be aware the a stack that you created a standalone from cannot be SAVED!

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: Put IT into more than one field

Post by Newbie4 » Wed Oct 19, 2022 6:22 pm

It sounds like you want the program to be run only once or not allow it to be run after someone has entered a company name.

Klaus is correct. You can not make a change to a stack and save it. No operating system allows an executable program to be modified (executable programs are stored in the "systems" folder which is Read-Only) This is for security reasons. It is the same in Windows and Mac. If you need to save info or data for your program, it has to be in a file written to the "Documents" folder which is Read and Write enabled.

If you want to control who can execute a program and save data, you have 2 viable options:
1: Create a "splash" stack to start up and call your "main" stack as a separate stack. The splash (startup) stack is put in the "system " folder and the main stack is placed in the "Documents" folder. Then you can modify it and save it there with with data
2: Use a "settings/"preferences/companyinfo" file which is stored in the "Documents" folder as a separate file.

With regard to your code, you can separate the initial tests for empty and the saving of info which would reduce the number of duplicate lines and make the logic simpler and easier to modify/debug. I took the liberty of refactoring your code to show you what I mean. It needs finished... depending on which way you decide to go. This example assumes that you are using a "companying" file

Code: Select all

global CompNameX
on mouseUp pMouseButton
   put "." into CompNameX
   
   // See if there is a saved companyinfo file
   // if so, get saved compname into global variable - CompNameX
   
   if CompNameX = "xyz" then
      quit
      // or exit
   end if
   
   if CompNameX = "." then
      ask "Enter the name of the business" 
      put it into CompNameX
      if CompNameX is empty then
         ask "Enter the name of the business"
         put it into CompNameX
         if  CompNameX is empty then
            ask "Enter the name of the business, Last Chance"
            put it into CompNameX
            if CompNameX is empty then 
               put "xyz" into CompNameX
               //Write out companyinfo file
               quit
            end if
         end if
      end if 
   end if
   
   put CompNameX into field "Compnamex"
   put CompNameX into field "Indequal1"
   put CompNameX into field "compnamex_inv" of cd "doxinv"
   // etc
   
end mouseUp
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Put IT into more than one field

Post by dunbarx » Wed Oct 19, 2022 6:43 pm

@ Newbie4

Your name on this forum may be a bit outdated. How about "regularOldLiveCoder4"?

Craig

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: Put IT into more than one field

Post by Newbie4 » Wed Oct 19, 2022 7:11 pm

@dunbarx

Good idea. But I am not sure if we can...

Thanks
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: Put IT into more than one field

Post by CAsba » Thu Oct 20, 2022 10:01 am

Hi,
OK, I'll have to rethink the strategy bit, but my pressing problem is still unresolved - the 'put' command is operational only on the same card as the command button, it is not finding the object on another card. (Chunk: object not found). This could be something I inadvertently set up (and subsequently forgot !), that is restricting the command; shooting in the dark here, could it be that something is set to modal or top level, for example, or some other non-understood choice I may have made somewhere ?

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: Put IT into more than one field

Post by CAsba » Thu Oct 20, 2022 10:09 am

Re my last,
should have read
Chunk: no such object

Post Reply