How can I write a Surfer script to prompt the user for a file?

This article contains a sample script for opening a dialog box to select a grid or data file to use, or to save an SRF file.

To run this script:

  1. Copy the script below, or download the attached BAS file: GetFilePath.bas.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer 16. 
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. 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.
  6. Click Script | Run to run the script.


'GetFilePath.bas shows how to open a dialog box to select a grid or
'data file to use, or to save an SRF file.


Sub Main
	Dim SurferApp As Object
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True

	Dim Plot As Object
	Set Plot = SurferApp.Documents.Add

'GetFilePath format is in the form of:
'default file name, extension(s), default file path, dialog title, and option value.
'See Help | BASIC Language Help, UserInput | GetFilePath for option values

'Choose a grid file for contour map
	gridfilepath = GetFilePath( , "grd",SurferApp.Path+"\samples\","Open Grid File",0)

	Dim MapFrame As Object
	Set MapFrame = Plot.Shapes.AddContourMap(GridFileName:=gridfilepath)

'Choose a data file for post map
	datafilepath = GetFilePath("demogrid.dat","dat;txt;csv;xlsx;xls",CurDir(),"Open Data File",0)

	Dim MapFrame2 As Object
	Set MapFrame2 = Plot.Shapes.AddPostMap(DataFileName:=datafilepath)

'Save to an SRF file
	SRFfile = GetFilePath ("default name" ,"srf", CurDir(),"Save SRF File",2)

End Sub


Updated November 13, 2018

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


Please sign in to leave a comment.