I don't like to use Global Variables because I believe it a best practice is to DELETE ALL OK when starting a
script---using this convention, you would delete all variables at the
start of the script.---this ensures that the script runs with
only the values entered in the execution of the currently executed
scripts. Thus, the use of global variables is negated.
At
the same time, it is often valuable to have access to global
variables. This is particularly true when using Dialog
Boxes/interactive scripts. With Dialog Boxes you often want to
capture the last values utilized in the execution of a script. For
example, you may want ACL to recall the selection of the previous
execution---thus, allowing the dialog boxes/interactive scripts to
have default values equal to the previous usage.
We
thus have two conflicting objectives. First, to ensure that the
values captured in a script are pertinent and accurate for the
current run of the script. Second, to enhance the effectiveness of
interactive scripts. I've written a few scripts that make this a
possibility. The first script, which would actually be one of the
last scripts run in a project, creates a .fil that preserves the
variable inputs from the project in a table called "Variable_Record".
The other two scripts are actually run near the start of the project
and interprets the values in the Variable_Record Table.
In
working with these scripts, I would initiate a dialog box or accept
command that inquires of the user if they wish to load saved values.
If the answer is yes, then it runs the script with those saved
values.
NOTE:
The next level of using this script, would be to create different
VARIABLE_RECORD tables as permanent records for the selections used
or to recreate prior selections!
NOTE:
This script is a proof of concept (it works in theory, but care
should be observed as it hasn't been tested
extensively.)
COM******************************
COM
This script is intended to be one of the last scripts run in the
execution of a
COM
a project or it is intended to be run right after ALL of the dialog
scripts
COM
are run. (NOTE: Best practice is to have ALL dialog scripts execute
before
COM
running analysis scripts.)
COM******************************
SET
SAFETY OFF
DEL
test1.log OK
DEL
test1.lix OK
DEL
FORMAT variable_record OK
DELETE
variable_record.fil OK
SET
LOG test1
DIS
VAR
SET
LOG
IMPORT
PRINT TO Temp1 "temp1.FIL" FROM "test1.LOG"
SERVER 1 0 RECORD "Detail" 0 1 0 TEST 0 2 AT 1,1,1 0 "E"
TEST 1 0 AT 1,1,0 0 "Log" TEST 1 0 AT 1,1,0 0 "Name"
TEST 1 0 AT 1,1,0 7 "Switching" FIELD "full_record"
C AT 1,1 SIZE 100,1 DEC 0 WID 88 PIC "" AS ""
OPEN Temp1
OPEN
TEMP1
DEFINE
FIELD f_var_name COMPUTED SUBSTR(SPLIT(full_record, " ",
1), 1, 33)
DEFINE
FIELD f_var_type COMPUTED sub(ALL(SUB(FULL_Record,at(1,"
",Full_record),100)),1,1)
DEFINE
FIELD f_var_value COMPUTED sub(ALL(SUB(FULL_Record,at(1,"
",FULL_record),100)),at(1," ",ALL(SUB(FULL_Record,at(1,"
",FULL_record),100))),100)
EXTRACT
f_var_name f_var_type F_var_value to
"Variable_Record.fil"
************************************************************
************************************************************
*************E02_Variable_Assign*******************************
*************************************************************
*************************************************************
COM********************************************************
COM
This script is control script that is run near the start of the
project.
COM********************************************************
OPEN
Variable_Record
COUNT
v_cntr
= count1
v_cnt
= 1
DO
E03_Variable_Assign WHILE v_cnt
<=V_cntr
************************************************************
************************************************************
*************E03_Variable_Assign*******************************
*************************************************************
*************************************************************
Open
Variable_Record
Locate
record %v_cnt%
Assign
v_temp = ALL(exclude(f_var_name,'"'))
IF
f_var_type ="C" Assign %v_temp% =
ALL(exclude(f_var_value,'"'))
IF
f_var_type ="D" Assign %v_temp% = f_var_value\
IF
f_var_type ="N" Assign %v_temp% =
VALUE(f_var_value,2)
v_cnt
= v_cnt +1