Page 1 of 1
Adding Card Fields to an Array
Posted: Sun Jun 12, 2011 5:50 pm
by townsend
Rather than hard coding all my SQL statements into a variable like tSQL,
I want to store them in an array, which will make editing them easier.
This code works fine in the Message Box.
It creates a keyed entry into the array, SQL.
Code: Select all
put "SELECT * FROM control" into SQL["select-all"]
Now I have two fields on my card: actualSQL & SQLkey.
When I take the same code and put it in a button like this:
Code: Select all
on MouseUp
put field actualSQL into SQL[field SQLkey]
end MouseUp
I get an execution error on syntax.
So then I try:
Code: Select all
put actualSQL into act
put SQLkey into ky
put act into SQL[ky]
Then the object names are inserted. So I think it needs something like
"value of actualSQL" or "text of SQLkey" but these don't work.
I've looked in the User Guide, the Dictionary and through Array Lessons.
What am I missing?
Re: Adding Card Fields to an Array
Posted: Mon Jun 13, 2011 12:11 am
by SparkOut
Very probably quotes, and a reference to the control identifier. And quite possibly "value" but not quite sure whether I have understood correctly, which likely I haven't. Does this work?
Code: Select all
put field "actualSQL" into SQL[(value(field "SQLkey"))]
Maybe just using : the text of field "SQLkey" in the right place would work.
Re: Adding Card Fields to an Array
Posted: Mon Jun 13, 2011 12:05 pm
by BvG
you probably want something like this:
Code: Select all
put field "actualSQL" into mySQLArray[field "actualSQL"]
and that should work. If it doesn't most likely the fields do not exist, or there's a type somewhere.
Re: Adding Card Fields to an Array
Posted: Mon Jun 13, 2011 4:54 pm
by townsend
Thanks guys-- I appreciate the help.
I finally figured out what the problem was. It wasn't syntax.
User Guide PDF wrote:Important: You must also use the global command at the start of a handler to make
an existing global variable available to a handler. While a global variable can be used by
any handler, you must do this in any handler you are going to use it in. If you don't
declare a global variable before using it, the handler will not take the global variable's
existence into account, and will simply create a local variable with the same name.
This means-- if you're going to use
Global myVariable, you're to need to put
that statement,
Global myVariable, in every handler it is referenced in.
With this in mind, I'm not even going to bother defining them at the top
of the Stack or Card Scripts. I'll just put then where they are needed.
A Custom Property on the other hand could be defined in one place
and referenced from anywhere without redefinition.
Re: Adding Card Fields to an Array
Posted: Mon Jun 13, 2011 6:33 pm
by BvG
actually, you can define variables and constants outside of handlers, in every script. That is the only thing that can exist outside a handler and still work. for example:
Code: Select all
global globX
constant constOffset = "42"
on mouseUp
put globX + constOffset
end mouseUp
Re: Adding Card Fields to an Array
Posted: Mon Jun 13, 2011 6:58 pm
by townsend
Excellent point! So if I have a script with a dozen handlers,
all I need to do is put the Globals, and Constants at the top.