This example describes the
steps required to access the COM object from Visual Basic. Building a simple
project will be described to illustrate this process. The Vektrex Scope driver
will be used as an example.
Step 1: Making
the COM Object Available to the Project
Once a new project is
created, select References from the Project Menu. A dialog similar to that
shown below will appear. This box contains a list of the registered COM
objects on the computer. Select the IVI Vektrex Scope object and press OK.

Step 2: Creating an Instance of
the Object
At the top of the Visual Basic Code window type
the line shown in the diagram below. The diagram shows Visual Basic’s
Intellisense in action, once the space after New is pressed a list of
possible options appears. Select VektrexScope. As well as creating the
object, this line of code sets MyScope to be a reference to the default
Interface inside the object – in this case the top-level interface of the
instrument specific functions.

Step 3: The
Form_Load Procedure
When a Visual Basic program
is run, the form_load procedure is executed first, so this is an ideal place
to place the call to the driver’s Initialize function. The diagram below shows
this code, and also shows the user starting to enter the code that will run
the Initialize function (at the bottom of the Intellisense window).

The next diagram shows the
help “tooltip” that is displayed when the spacebar is pressed after
Initialize.

The finished Form_Load
procedure is shown below:
If more help is needed to
complete the function, click on the word
Initialize and press the F1 key, this will open the driver’s help file
to the appropriate place.
Step 4: Coding a Function
The diagram below shows a
completed Visual Basic procedure that uses a property in the Instrument
Specific Acquisition Interface. Once again, Intellisense will help with each step,
including listing options for any enumerated types. This code
assumes that on the Visual Basic form is a button named Get Number of
Averages for the user to press and a text box named Averages where
the returned value will be displayed. This code snippet also shows how the
procedures perform error handling – if an error occurs, an error handler
routine will be called.
Step 5: Tidying Up at the end of
the Program
The code snippet below is run when the user presses a button
on the form named Close.
Here the COM object’s Close function is run,
the references are released and the program is stopped.
Step 6: Error Handler
If an error occurs inside the COM object,
information about what happened is passed back to Visual Basic inside an error
object. This simple error handler causes a dialog box to appear with the error
number and description. When the user clears the dialog box, program execution
continues.
Discussion
This example has shown how to
create a client application in Visual Basic using the instrument specific
interfaces. Note that this application is not using any of the
interchangeability features (it is not using the compliant interfaces and it
references a particular driver, VektrexScope, directly).