Page 1 of 1

global variable in answer button

Posted: Wed Nov 17, 2010 5:48 pm
by jesse
I am trying to create a Date Time Stamp I can store in a global variable that can be accessed
when a different button is clicked. The date time stamp is set/updated when the user picks an item from a list
field

Here is my list field code

Code: Select all

on menuPick pItemName
   switch pItemName
   end switch
global gDateTimeStamp

      put the date && the time into  gDateTimeStamp
      put gDateTimeStamp into field "Current Date Time Stamp" 
end menuPick
here is the code I was trying to use to show the value from another button:

Code: Select all

on mouseUp  
answer gDateTimeStamp
end mouseUp

Re: global variable in answer button

Posted: Wed Nov 17, 2010 6:03 pm
by Dixie
Jesse...
I 've put the following script in a popUp menu button...

Code: Select all

global dateTime

on menuPick pItemName
   switch pItemName
     
      default
         put the seconds into dateTime
         convert dateTime to dateItems
   end switch
end menuPick
and the following in another button on the card

Code: Select all

global dateTime

on mouseUp
   put dateTime
end mouseUp
Hope this helps...

Dixie

Re: global variable in answer button

Posted: Wed Nov 17, 2010 6:09 pm
by Klaus
Yes, global variables need to be declared in the handler/script where and before they are used.

Re: global variable in answer button

Posted: Wed Nov 17, 2010 6:35 pm
by jesse
Hi Dixie,

Thanks for that. I still cant get answer to pop up the variable.
In the other button on the card I have

answer gDateTimeStamp (thats my global variable)
but i dont see the variable i just see the gDateTimeStamp show up in the answer box that pops up. Am I doing something wrong?

Re: global variable in answer button

Posted: Wed Nov 17, 2010 6:39 pm
by Dixie
jesse

put this script in your 'other' button... declare your global variable in the script of the button... you have not declared yours in your script of the other button.

Code: Select all

global dateTime

on mouseUp
   answer dateTime
end mouseUp
Is that what you want ?

be well

Dixie

Re: global variable in answer button

Posted: Wed Nov 17, 2010 7:41 pm
by jesse
got it. thanks!