Common or occasionally expected errors can prevent a script from running to completion. Error handling commands enable a script to execute entirely regardless of error.
To run this script:
- Copy the script below, or download the attached BAS file: OnError.bas.
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
- Double click on Scripter.exe to launch Scripter.
- Press Ctrl+A to select all of the existing lines then press Delete.
- If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
- Click Script | Run to run the script.
*********
'OnError.bas shows an example of how to set error handling in Scripter
'==================================
Sub Main
Dim SurferApp As Object
Set SurferApp = CreateObject("Surfer.Application")
SurferApp.Visible = True
Dim Plot As Object
Set Plot = SurferApp.Documents.Add
On Error GoTo X
SurferApp.GridData (DataFile:="c:\temp\ElevationData.xls", xCol:=2, yCol:=3, zCol:=3, OutGrid:="C:\temp\test.grd")
X: Err.Clear
Dim MapFrame As Object
Set MapFrame = Plot.Shapes.AddContourMap(GridFileName:="C:\temp\ElevationGrid.grd")
Plot.SaveAs(FileName:="C:\temp\Elevation.srf")
End Sub
Updated November 2021
Comments
Please sign in to leave a comment.