Page 1 of 1

How can I check for a variable not defined ?

Posted: Thu Apr 26, 2007 3:49 am
by maurosturaro
Using a Persistent variable I need to set it to a default value if it is not already initialized from a previous execution.

I've seen from the debugger that a command like
Set Variable SELECT to $MyVariable$
takes the value "$MyVariable$" (the name surrounded by $ sign) if the variable is not defined, so I've try to check if the variable SELECT contain a $ sign.
... but I've got a lot of strange error :
1) Runtime error in insall: cannot open the file "{omiss}\\Temp\\mia13\\.dfm" (note that file name is empty)
2) Runtime error in install: List index out of bouns (25)
depend on how I try to test it.

could you help me ?

Posted: Thu Apr 26, 2007 7:02 am
by MichaelNesmith
Interesting case...I don't think testing if a variable has been defined is supported (as confirmed by your test results).

The proper approach is to make sure the persistent variable is always defined on each run of your software. This will be guaranteed if you make sure you define it the very first time setup runs. There is a nice place to do this in your script, the same place that initializes the TARGETDIR and STARTMENU variables to their initial values (these variables are persisted automatically).

Posted: Thu Apr 26, 2007 7:41 am
by maurosturaro
But with the new #LOADOLDDATA# I don't know if the variable is already defined, by loading of setup data from an older prduct version, or this is a first installation and I must initialize all my variables.

Also I need to modify the initialization of TARGETDIR and STARTMENU variables so it's previous value is not overvritten by default values.

Posted: Thu Apr 26, 2007 9:19 am
by MichaelNesmith
That's why LOADOLDDATA is optional ;)

Workaround

Posted: Fri Apr 27, 2007 10:06 am
by maurosturaro
The following code work.
The parse command is the only way I found to set a variable to a dollar sign, getting the first of a two dollar sign
:idea:

Code: Select all


Comment: load only 1 caracter
Parse String $$ into Variables DOLLAR and  (Split at position from start)
Set Variable SELECTED to $MYVARIABLE$
if Variable MYVARIABLE Contains $DOLLAR$
  Comment: initialize default value
  Set Persistent Variable MYVARIABLE to INITIALVALUE
end

:!: