Using the VISA C API in Microsoft Visual Basic 6

Agilent VISA.NET

Using the VISA C API in Microsoft Visual Basic 6

Using VISA to communicate with instruments using the VISA C API in Microsoft Visual Basic 6 (VB6) is relatively straightforward for most of the VISA functions.  However, there are several areas of I/O which can cause difficulty. This topic provides details on those areas.

Include visa32.bas

To use the VISA C API in VB6, include the visa32.bas file in your projects.  If you installed the Agilent IO Libraries Suite using the default VISA path. Refer to VISA Directories topic for specific information)..

We strongly recommend copying visa32.bas to your local project directory, so that any modifications you may make to it will be local to your project and won't change the master installed copy of that file.  Once you have placed visa32.bas in your project directory, you will need to use the Project > Add Module menu choice to add visa32.bas to your project.  Once this module is added, you will be able to call VISA functions from your VB6 project.

viRead and viWrite

The viRead and viWrite function declarations use the String data type for their buffer pointers, but users often want to read and write numeric array data. See Notes on Using viRead/viWrite in Visual Basic 6 for more details and examples.

Formatted I/O

The viPrintf, viScanf, and viQueryf VISA functions take variable argument lists in C.  Some of viScanf's and viQueryf's variable arguments are references to primitive (byte, integer, long, float, etc.) types, meaning that the values themselves can be changed by the function.  There is no equivalent in VB6 for variable argument lists with reference arguments, so no direct translation is available.  Instead we use the 'V' form of these functions (viVPrintf, viVScanf, and viVQueryf),  in conjunction with the undocumented VB6 VarPtr function to create an array of pointers to arguments than can be passed to the VISA functions.

The examples below are presented as self-contained VB6 Sub's with comments explaining the various features.  You can modify and adapt the code in the examples to your specific situation.

    • viVPrintf/viVScanf Example using String
    • viVScanf Example Returning a Double Array
    • viVScanf Example Reading an IEEE 488 Definite Length Block and Returning a Byte Array
    • viVScanf Example Reading an IEEE 488 Indefinite Length Block and Returning a Byte Array
    • viVQueryf Example with String and Indefinite Length Block

See Also

viRead, viWrite, viVPrintf, viVScanf, viVQueryfVB6 Types and VISA C Types Reference
Notes on Using viRead/viWrite in Visual Basic 6

viVPrintf/viVScanf Example using String

viVScanf Example Returning a Double Array

viVScanf Example Reading an IEEE 488 Definite Length Block and Returning a Byte Array

viVScanf Example Reading an IEEE 488 Indefinite Length Block and Returning a Byte Array

viVQueryf
Example with String and Indefinite Length Block