Documents Collection Script

This script demonstrates all the methods and properties in the Documents collection. If you wish to run the script, open Scripter and then open DocumentsCollection.bas from the Surfer Samples folder.

' DocumentsCollection.bas illustrates the properties and

' methods of the Surfer Documents Collection. - TB - 25 Oct 01

 

Sub Main

 

Debug.Print "----- DocumentsCollecton.bas - ";Time;" -----"

 

'Get existing Surfer instance, or create a new one If none exists.

On Error Resume Next 'Turn off error reporting.

Set SurferApp = GetObject(,"Surfer.Application")

If Err.Number<>0 Or SurferApp.Documents.Count = 0 Then

Set SurferApp = CreateObject("Surfer.Application")

SurferApp.Documents.Add(srfDocPlot)

End If

On Error GoTo 0 'Turn on error reporting.

 

Debug.Print "Surfer ";SurferApp.Version

SurferApp.Visible = True

SurferApp.WindowState = srfWindowStateNormal

SurferApp.Width = 600

SurferApp.Height = 400

SurferApp.Windows(1).Zoom(srfZoomPage)

 

Set plotdoc1 = SurferApp.Documents(1)

Set plotwin1 = SurferApp.Windows(1)

 

path1 = SurferApp.Path+"\samples\"

file1 = path1+"demogrid"

 

Set shapes1 = plotdoc1.Shapes

 

'-------------------------------------------------------

' Documents Collection Properties.

'-------------------------------------------------------

Debug.Print "-- Documents Collection Properties --"

 

Set docs1 = SurferApp.Documents

Debug.Print "docs1.Application = ";docs1.Application

Debug.Print "docs1.Count = ";docs1.Count

Debug.Print "docs1.Parent = ";docs1.Parent

 

'-------------------------------------------------------

' Documents Collection Methods.

'-------------------------------------------------------

Debug.Print "-- Documents Collection Methods --"

docs1.Add (srfDocPlot) 'Add a new plot document.

Debug.Print "Add"

 

AppActivate "Surfer"

'Close all docs. Ask to save if changes have been made.

Debug.Print "CloseAll"

docs1.CloseAll(SaveChanges:=srfSaveChangesAsk)

 

'Use Item to refernce a particular document.

Debug.Print "Item"

docs1.Add (srfDocPlot) 'Add a new plot document.

docs1.Add (srfDocWks) 'Add a new worksheet document.

Set plotdoc1 = docs1.Item(1)

' Item is the default method, so the above statement can be written

' with shorter syntax.

Set plotdoc1 = docs1(1)

' The document name can be used as the Item index.

' Set plotdoc1 = docs1("Plot1")

SurferApp.Windows.Arrange(srfTileVert)

Wait 3

docs1.CloseAll(srfSaveChangesAsk)

 

' Open a file in a document.

Debug.Print "Open"

Set plotdoc2 = docs1.Open(path1+"Stacked Maps.srf") 'A Plot document.

Set wksdoc1 = docs1.Open(path1+"demogrid.dat") 'A Worksheet document.

Set griddoc1 = docs1.Open(path1+"demogrid.grd") 'A Grid document.

SurferApp.Windows.Arrange(srfTileVert)

Wait 3

' Prompt to save changes to all documents, and leave them open.

Debug.Print "SaveAll"

docs1.SaveAll(True)

' Close all docs and prompt to save changes.

docs1.CloseAll(srfSaveChangesAsk)

End Sub