global variables

hershrev hershbp at realtorsgroup.us
Wed Feb 4 20:36:21 EST 2004


On Wednesday, February 4, 2004, at 08:08 PM, Sarah Reichelt wrote:

> My attempt at an explanation has obviously failed :-) so I suggest you 
> search the Transcript dictionary for "global". From the "See also" 
> menu, read the article titled "About containers, variables and sources 
> of value".
>
> Basically: if you declare your variable in the stack script, outside 
> any handler, then all the handlers in the stack script can use it. If 
> you need to use it in another object's script, you need to declare it 
> again in that script, either inside or outside the handlers.
Yes , this is what I wanted to know (or make sure)
And while we are at it , why doesn't this work , meaning the 
gmyEditLine remains empty

global myQuery,mySelectedLine,myDbId,myEditLine
on mouseUp
   put line mySelectedLine of myPkid into myEditLine
   put "SELECT company,last_name FROM contacts WHERE (pk ='"& myEditLine 
&"')" into myQuery
   put revDataFromQuery(,,myDbId,myQuery)into field "find Field"
end mouseUp

And if i do it in the message box:  put line mySelectedLine of myPkid 
into myEditLine, it does work
Thanks to Sarah


>
> Just one more thing: "global mygabc = 3" will not work. You have to 
> initialize your global inside a handler using the form "put 3 into 
> mygabc".
>
> Cheers,
> Sarah
>
> On 5 Feb 2004, at 10:53 am, hershrev wrote:
>
>>
>> On Wednesday, February 4, 2004, at 07:27 PM, Sarah Reichelt wrote:
>>
>>> A global works everywhere, but it has to be declared in each place 
>>> where you need to use it. i.e. you must include the line "global 
>>> gMyGlobalVar" in every script that needs access to the global 
>>> gMyGlobalVar. If you declare it in a handler, only that handler sees 
>>> it, but if you declare it outside the handler, all the handlers in 
>>> that script can see it without needing a separate declaration in 
>>> each handler. Even though globals are accessible everywhere, you 
>>> must tell each script or handler that they are globals before you 
>>> use them, otherwise they will just assume you are creating a local 
>>> variable of the same name.
>> That means if I declare a "global mygabc =3' out side of a scrip in a 
>> stack ,when I need it in a button I have to declare it again
>> "global mygabc" in the button script.
>> and if I declare it in a handler in a stack ????? Where is the 
>> difference ??
>> Thanks
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>



More information about the use-livecode mailing list