Follow

My script works in Surfer 9, but in newer versions I get an error: Operand/operator type mismatch. It stops on a line inside a loop. Why?

This article explains why a Surfer 9 script may receive an error about an operand/operator type mismatch when run in Scripter for a newer version of Surfer.
 

Surfer 10 and above comes with a new version of Scripter. The old scripter (Surfer 7, 8 and 9) was rather forgiving about concatenating a number to a string, such as when you use the loop variable (a number) as part of a string in a command line. The new Scripter enforces the BASIC language rules a bit more stringently, and you need to convert the number to a string explicitly using the BASIC Format statement.

 

For example, this portion of a script works in Surfer 9, but fails in Surfer 10 on the red line:

For i = 1 To 3
      Dim Plot, Map As Object
      Set Plot = SurferApp.Documents.Add
      Path = "c:\temp\SAMPLE"+i
      Set Map = Plot.Shapes.AddContourMap(GridFileName:=Path+".grd")
 Next i

 

See how “i” is used as part of the string in the Path statement, but really “i” is a number (1 to 3). As mentioned above, the new Scripter doesn’t have a way to convert a number (i) to a string (part of the file path) and so you have a numbers and string in the command line and you get the type mismatch error. To fix this, you need to use the Format statement to convert the number to a string:

For i = 1 To 3
    Dim Plot, Map As Object
    Set Plot = SurferApp.Documents.Add
    Path = "c:\temp\SAMPLE"+Format(i)
    Set Map = Plot.Shapes.AddContourMap(GridFileName:=Path+".grd")
Next i
 

Updated February 14, 2017

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.