logo

img

Knowledgebase Home | Contact Knowledgebase Home | Contact
Search the Knowledgebase Browse by Category
My script works in Surfer 9, but in Surfer 10 I get an error: Operand/operator type mismatch. It stops on a line inside a loop. Why?
User Opinions
100% thumbs up 0% thumbs down

How would you rate this answer?
Helpful
Not helpful
Surfer 10 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 As Object

  Set Plot = SurferApp.Documents.Add

  Path = "c:\temp\SAMPLE"+i

  Dim Map As Object

  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 As Object

  Set Plot = SurferApp.Documents.Add

  Path = "c:\temp\SAMPLE"+Format(i)

  Dim Map As Object

  Set Map = Plot.Shapes.AddContourMap(GridFileName:=Path+".grd")

 Next i

Visitor Comments
No visitor comments posted. Post a comment
Related Questions
Attachments
No attachments were found.
Products