How can I add the correct value into column A of a BLN header row with Surfer automation?

This article contains a sample script for correcting the header values of a BLN file. It searches the BLN file using the BLN flag value in Column B, and automatically enters the correct number of points in Column A for each object in the BLN file.

To run this script:

  1. Copy the script below, download the attached BAS file: BLNheader.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.


'This script searches the BLN file using the BLN flag value in
'Column B and then automatically enters the correct number of points
'in the header line in Column A. This is useful if you have a long
'BLN file and the header count is off for a few objects.


Sub Main

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

    'Specifies input data
    BLNFile$ = GetFilePath( , "bln",path1, "Select bln file")
    If BLNFile$ ="" Then End

    'Opens BLN file
    Dim Wks As Object
    Set Wks = SurferApp.Documents.Open(FileName:=BLNFile$)

    'Defines worksheet range as columns A and B
    Dim WksRange As Object
    Set WksRange = Wks.Columns(Col1:=1, Col2:=2)

    'Define the header flag in Column B for the objects in the BLN file
    Flag= Val(InputBox$("Enter the flag value in Column B in the BLN file. It must be the same for each object in the BLN. Usually, this is a 0 or 1.", "Specify Flag Value", "1"))

    'Sets BLN header
    RowToChange = 0

    For row=1 To WksRange.RowCount
        'If Grid.IsBlanked(row,col) = True Then Grid.SetNode(row,col) = 0
        If Wks.Cells("B"+Format(row)).Value=Flag Then
            If RowToChange >0 Then
                Wks.Cells("A"+ RowToChange).Value = Format(row)-RowToChange-1
            End If
            RowToChange = Format(row)
        End If
        If Format(row) = WksRange.RowCount Then
            Wks.Cells("A"+RowToChange).Value = Format(row)-RowToChange
        End If
    Next row

    'Saves BLN file
    BLNfilepath = Left(BLNFile$,InStrRev(BLNFile$,".")-1) + "_Corrected.bln
    Debug.Print "File saved as ";BLNfilepath

End Sub



Updated November 08, 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.