Variable handling suggestions?


#1

Hello,

I have a large procedure which uses many variables, in some cases, the variable will not have a value depending on the user selecting different options. I am used to initializing variables with myVariable="". I now not sure this was a good habit to form, in Panorama X I will get the message “field or variable [myVariable] does not exist”. I can throw a lot of if statements at it but with the size and complexity of my procedure I am hoping there might be a simpler way. Any ideas?


#2

You could use

Define MyVariable, ""

If the variable already exists, and has a value, that statement does nothing. If it exists, but doesn’t have a value, it gives it the value you specified (in this case a blank.) If the variable doesn’t exist at all, it creates it as a FileGlobal, and gives it the specified value.

I’m not sure why initializing the variable is causing that problem. To get that error, when you are assigning a value to the variable, it either doesn’t exist at all, or it belongs to a different database than the one that is active when you try to do the assignment.


#3

Hi Dave,

Doesn’t myVariable="" do the same thing as define myVariable,"" ? In this case the variables are all in the same database.


#4

This error message means that the variable was never set up with a local, global, or fileglobal statement. Variables can also be set up automatically by some form objects, for example Text Editor objects and Data Butt objects.

This has nothing to do with Panorama X, Panorama 6 worked the exact same way. You can’t assign a value to a variable until you have set it up. If you want to make sure, do the setup right before the assignment.

fileglobal myVariable
myVariable=""

The define statement does not replace the statement for setting up the variable. It is just like the assign statement (x=y), but if the variable already has a value, the define statement doesn’t change the value.


#5

Description

This statement defines a value for a variable, unless that variable already has a value. In other words, this statement will initialize the variable if the variable’s value has not been defined yet, but if the variable already has a value it will not touch the value. (If the variable doesn’t exist at all, it is created as a fileglobal variable and given the specified value.)

The define statement will setup the variable if it doesn’t already exist. It will set it up as a FileGlibal. You could still get the “Field or variable does not exist” error if a different file was active when you tried to use it.


#6

Dave, you’re right! (what else is new?) I must have known that at some point, because I see that I wrote ten lines of code to make that happen, but I had entirely forgotten that the define statement did that. Hmm, I see that it is documented in the Panorama X Help also.

I tested it just now and Panorama 6 did the same thing, though it is not documented in the Panorama 6 Programming Reference wizard (maybe it is in the Formulas & Programming PDF somewhere).