Using Variables in Command Options

Top  Previous  Next

 

FileLink script command options may not be specified using variables directly. The following is an example of a script command with an option:

 

USEPORT /parity=none

 

In this case none is a literal string (without quotation marks) and it cannot be replaced with a variable. However, there is an indirect way that this can be done. This involves the building of a complete command in a variable and using the PERFORM script command to run it.

 

For example, let's assume that you wish to set some COM port parameters that are not known until the script is run. The command might look like the following:

 

USEPORT /baudrate=9600 /parity=none

 

Say that the script prompts the user for the baudrate and parity settings and these are assigned to script variables baud and par. You might be inclined to try something like:
 

USEPORT /baudrate=baud /parity=par  ;;Wrong!

 

This will result in wrong baud rate and parity values (the variable names, not their values) being provided to the USEPORT command. The supported method would be:
 

SET cmd = "USEPORT /baudrate=" & baud & " /parity=" & par

PERFORM cmd

 

In another example, let's assume that you wish to control the reading of text file using the READFILE command with /record option, but the record number varies and you wish to use a variable to specify which record to read. Normally the command would look something like the following:

 

READFILE "datafile" datarecord /record=1

 

The /record option accepts a numeric constant only. Using a variable, you would like do something like:

 

SETNUM rec = 10

READFILE "datafile" datarecord /record=rec  ;;WRONG!!

 

The supported method is:

 

SET file = "datafile"

SETNUM rec = 10

SET cmd = "READFILE " & file & " /record=" & rec

PERFORM cmd

 

This method may be used on any FileLink script command that uses options.