This article gives helpful hints for converting your Surfer 6 scripts into scripts that will run successfully in newer versions of Scripter.
The newer Surfer automation model, introduced in Surfer 7, is different than Surfer 6. Surfer 7 still supported the older Surfer 6 automation model in addition to the new model, but support for the older model was completely dropped in Surfer 8. Surfer 6 scripts may require considerable revision to work with Surfer 8+.
Unfortunately, there is not an automatic way to convert scripts from the Surfer 6 automation model to the new model. To help learn the newer automation model, I suggest starting from the Object Hierarchy graphics in the Help file. Several changes were required that may break old script files. Most of these are a result of moving to a VBA-compatible scripting language:
- When a wireframe plot is selected the default name is "Wireframe" rather than "Surface".
- "Surfer.App" is the Application object for the old Surfer 6 interface. "Surfer.Application" is the new Surfer 7 Automation model.
- The commands Surfer.FileNew(int iDoc) and Surfer.FileOpen(FileName,iDoc) no longer support iDoc==2. This created an editor document which is no longer supported. This will silently fail to minimize the effect on existing scripts.
- The new Scripter requires named arguments to be specified with := whereas the old Scripter required the single =.
- Scripter statements must be contained within a Sub block. The main program should be within a "Sub Main", "End Sub" block. Surfer 6 Scripter allowed stand-alone statements outside blocks. The old "End" statement should be changed to "End Sub"
- Subroutines used to be specified by labels. They now must be specified with "Sub XXX" and "End Sub" statements where XXX is the old subroutine label.
- The old "gosub" statement is no longer allowed. Delete it and call the subroutine directly. For example "gosub DoWork" should now just be "DoWork".
- The old Print statement is not supported. Use Debug.Print or MsgBox.
- Arrays must be dimensioned with the dim statement.
- Global variables must be declared outside the body of sub blocks.
- It is not possible to jump to labels in other subroutines.
- The \ line continuation character is not allowed. You need to use the underscore character _ for the equivalent functionality.
- Comments are not allowed after the line continuation character _.
- The Surfer 6 macro command FileNewWindow() always returns true (success).
- If Surfer 7 is started via Automation, the default directory is set to the applications startup directory. It used to be set to the Windows System directory.
- Surfer 7 Scripter uses End If (space between end and if) and Surfer 6 Scripter uses Endif (no space).
- Surfer 7 Scripter requires Option Explicit to be declared prior to the Sub .. End Sub. Surfer 6 Scripter does not support Sub .. End Sub, so Option Explicit can be declared anywhere.
- Surfer 7 Scripter does not allow the variable type suffix characters (%$#?&@!) in the DIM statement with the As Type syntax and Surfer 6 Scripter does allow it, e.g.
Surfer 7 Scripter:
DIM a As String DIM b$ DIM c$ As String 'ERROR Unexpected text a$ = "Test" 'or a = "Test2" 'both ways work, a = a$
Surfer 6 Scripter:
DIM a$ As String a$ = "Test" a = "Test" 'ERROR Type Mismatch, a <> a$
Some additional differences between Surfer 6 automation and the Surfer 7 automation model (used in all subsequent versions) are:
- The Surfer 6 Scripter time$() and date$() functions display an error message in Surfer 7 Scripter: "Function is defined with a different value type." Use the Surfer 7 Scripter functions time() and date(), or time and date with no parentheses (no $).
- The Surfer 6 Scripter sleep() function is not supported in Surfer 7 Scripter, which displays the message "Expecting an existing scalar var". Use the Surfer 7 Scripter wait() function, or wait without parentheses.
- The Surfer 6 Scripter function cls() to clear the output window is not supported in Surfer 7 Scripter.
- Surfer 7 Scripter uses If .. End If (note space in End If). Surfer 6 Scripter uses If .. Endif (no spaces in Endif). Attempting to run a script in Surfer 7 Scripter with Endif displays the error message "Expecting an existing scalar var".
- Surfer 7 Scripter treats a variable with a suffix as the same variable without the suffix, and Surfer 6 treats them as different variables.
Surfer 7 Scripter:
DIM a As String a = "Text1" a$ = "Text2" Debug.Print a$;" ";a 'Prints "Text2 Text2", a$ = a
Surfer 6 Scripter:
DIM a As String DIM a$ As String a = "Text1" a$ = "Text2" print a;" ";a$ 'Prints "Text1 Text2", a$ <> a
Updated February 14, 2017