The find & replace function can be invaluable in certain workflows. For example, you may want to change the null value in a dataset from -999 to 0. The script below shows how to automate this function in Surfer's worksheet.
To run this script:
- Copy the script below, or download the attached BAS file: Replace.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.
*********
'Replace.bas shows how to use the Edit | Replace function in automation 'to replace a value in the worksheet with another value. '===================================== Sub Main Dim SurferApp As Object Set SurferApp = CreateObject("Surfer.Application") SurferApp.Visible = True 'Open the worksheet document Set Wks = SurferApp.Documents.Open(SurferApp.Path+"\Samples\demogrid.dat") 'Specify the worksheet range Set WksRange = Wks.Columns(Col1:=1, Col2:=2) 'Replace "4" with the text "test" Set After = Wks.Range(1, "A", 1, "A") 'First cell WksRange.Replace(TargetStr:="4", ReplaceStr:="test", Current:=After, Scope:=wksFindScopeEntire, Method:=wksFindPhrase, ReplaceAll:=True) End Sub
Updated November 2021
Comments
Please sign in to leave a comment.