global variable in answer button

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
jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

global variable in answer button

Post by jesse » Wed Nov 17, 2010 5:48 pm

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
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: global variable in answer button

Post by Dixie » Wed Nov 17, 2010 6:03 pm

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

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

Re: global variable in answer button

Post by Klaus » Wed Nov 17, 2010 6:09 pm

Yes, global variables need to be declared in the handler/script where and before they are used.

jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

Re: global variable in answer button

Post by jesse » Wed Nov 17, 2010 6:35 pm

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?
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: global variable in answer button

Post by Dixie » Wed Nov 17, 2010 6:39 pm

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

jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

Re: global variable in answer button

Post by jesse » Wed Nov 17, 2010 7:41 pm

got it. thanks!
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392

Post Reply