To loop through having a user select a data file, gridding it, and creating a map from the grid, you can use a "Do" loop. Start with Do, enter all the commands you want to loop, and end with Loop to go back to the beginning. Use If InFile = "" Then Exit Do to exit the loop. Below is a full script example of this.
To run this script:
- Copy the script below.
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer 14\Scripter.
- Double click on Scripter.exe to launch Scripter.
- Press Ctrl+A to select all of the existing lines then press Delete.
- Press Ctrl+V to paste it into Scripter.
- Click Script | Run to run the script.
Sub Main Dim SurferApp As Object Set SurferApp = CreateObject("Surfer.Application") SurferApp.Visible = True Do Dim Plot As Object Set Plot = SurferApp.Documents.Add 'Prompt the user for the name of the data file to process. InFile = GetFilePath(" ","DAT;TXT;CSV;XLS",CurDir(), "Select Data File", 0) If InFile = "" Then Exit Do 'Get file name without the extension (for example, "week5.txt becomse "week5") BaseName = InFile ExtStart = InStrRev(InFile, ".") If ExtStart >1 Then BaseName = Left(InFile,ExtStart-1) 'Create a grid from the specified data file using the kriging algorithm GridFile = BaseName + ".grd" SurferApp.GridData (DataFile:= InFile, OutGrid:= GridFile) Dim Map As Object Set Map = Plot.Shapes.AddContourMap(GridFileName:=GridFile) Loop End Sub
Updated February 14, 2017