How can I find out the distance between my first two digitized points in Surfer Scripter?

This article contains a sample script for calculating the distance between the first two digitized points.

To run this script:

  1. Copy the script below, or download the attached BAS file: DistanceCalc.bas.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer 14\Scripter.
  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.


'DistanceCalc.bas calculates the distance between the first
'two digitized points recorded in the Surfer "Digtized Coordinates - digit.bln" window.

Sub Main
	Debug.Print "----- ";Time;" -----"
	On Error GoTo err1
	Set surf = GetObject(,"surfer.application")
	On Error GoTo 0
	On Error GoTo err2

'For Surfer 10
	AppActivate "Digitized Coordinates - digitized.bln"

	On Error GoTo 0

SendKeys "%E"
Wait .5
SendKeys "S"
Wait .5
SendKeys "^C"
Wait .5

	AppActivate "DistanceCalc"
	text1 = Clipboard
	'For i = 1 To Len(text1)
	'	Debug.Print Mid(text1,i,1);" ";
	'Next i

	points1 = Split(text1,Chr(10))
	'For i = 0 To UBound(points1)
	'	Debug.Print i;": ";points1(i)
	'Next i

	x1 = Val(Split(points1(0),",")(0))
	y1 = Val(Split(points1(0),",")(1))
	x2 = Val(Split(points1(1),",")(0))
	Debug.Print x1;" ";y1;" ";x2
	y2 = Val(Split(points1(1),",")(1))

	'x1 = Val(Left(points1(0),InStr(points1(0),",")-1))
	'y1 = Val(Mid(points1(0),InStr(points1(0),",")+2))
	'x2 = Val(Left(points1(1),InStr(points1(1),",")-1))
	'y2 = Val(Mid(points1(1),InStr(points1(1),",")+2))
	dist = Sqr(Power(x2-x1,2) + Power(y2-y1,2))
	Debug.Print "Distance: ";dist
	Debug.Print " (";x1;",";y1;")"
	Debug.Print " (";x2;",";y2;")"
	MsgBox("Distance: "+dist+vbCrLf+ _
	  "  ("+x1+","+y1+")"+vbCrLf+ _
	  "  ("+x2+","+y2+")","Distance")

	MsgBox("Start Surfer, right-click on map, digitize two points, "+ vbCrLf + _
		"digitize two points, and run DistanceCalc.bas in Scripter.", _
		,"Can Not Find Surfer")

	MsgBox("Digitized Coordinates - digitized.bln "+Err.Description+vbCrLf+vbCrLf+ _
		"Start Surfer,"+vbCrLf+ _
		"right-click on a map," + vbCrLf + _
		"digitize two points,"+ vbCrLf + _
		"and run DistanceCalc.bas in Scripter.")
End Sub
Function Power(X,Y)
    P = 1
    For I = 1 To Y
        P = P*X
    Next I
    Power = P
End Function



Updated February 13, 2017

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


Please sign in to leave a comment.