How To: Launch ArcView from Visual Basic
In this example, the Visual Basic application sends Avenue requests to ArcView that create new documents, such as views and layouts. Additionally, the application can query ArcView to obtain the current active document. The Visual Basic application is the destination application, while ArcView is the source application.
Visual Basic and ArcView must be installed to perform the following steps.
- Start Visual Basic and Form1 will be created by default.
- Create the following controls with the following properties on Form1, then resize the form so that it neatly contains the controls.
Object Property Setting
Text Box Name txtDDE
Command Button Caption Send Request
Combo Box Name cboDocType
- Add the following code to the general declaration section of Form1:
Const NONE = 0, MANUAL = 2
Sub Startup() 'Note: Visual Basic will create this subroutine
'in a separate window from the general declarations
Const DDE_NO_APP = 282 'error if no response
'see Trappable errors
'this will start ArcView if it isn't running
On Error GoTo FireUp
txtDDE.LinkMode = NONE 'Clear DDE Link
txtDDE.LinkTopic = "ArcView|System" 'Set up conversation
txtDDE.LinkMode = MANUAL 'Establish a manual link
If Err = DDE_NO_APP Then
ChDir "C:\esri\av_gis30\arcview\bin32" ' wherever ArcView was installed
' the ChDir is required
t = Shell("arcview", 1)
t = DoEvents() 'process Windows events
MsgBox "Unknown error."
- Add the following code to the Form_Load event procedure:
Sub Form_Load ()
cboDocType.text = ""
Startup 'calls startup procedure
- Add the following code to the Form_Unload event procedure:
Sub Form_Unload (Cancel As Integer)
txtDDE.LinkMode = NONE 'Close DDE conversation
- Add the following code to the cboDocType_Click event procedure:
cmd = "theDoc = av.GetProject.AddDoc(" & cboDocType & ".make) av.GetProject.GetSelectedDocs.Get(0).GetWin.Open "
- Add the following code to the cmdRequest_Click event procedure:
Sub cmdRequest_Click ()
'When selected this button will request an update of
'information from the source application to the
'LinkItem can be any Avenue script that returns a value
txtDDE.LinkItem = "av.GetActiveDoc.GetName"
- Save your Visual Basic project and make an .EXE file.
You can now run the Visual Basic application. If ArcView is not running, the application will start it. Choosing a document name from the dropdown combo box creates a document in ArcView. To request the current active document click the Send Request button. The name of the document displays in the text box.
In this example, all DDE communication passes through the text box. In Visual Basic, any text box, picture box, or label can be the destination in a conversation, while any form can be a source.