The Fundamentals of Building Applications with NI-DAQChapter 4
PC-OPDIO-16 User Manual 4-14 © National Instruments Corporation
Creating a Windows Application Using Microsoft Visual BasicTo use the NI-DAQ functions, you must use the NI-DAQ DLL. Follow this procedure:
1. Create your forms and code as you would for any other Visual Basic program, calling
NI-DAQ functions as typical function calls.
2. Prototype any NI-DAQ routines used in your application. You can do this by adding the
NI-DAQ header module WDAQ_VB.BAS in the NI-DAQ VB_EX directory. Go to the File
menu and select the Add File option. Then, using the file dialog box, find WDAQ_VB.BAS
and click on the OK button. Verify the file’s existence in the project window. This header
file will prototype all NI-DAQ functions.
Note: Use WDAQR_VB.BAS if you are using NI-DAQ memory management functions. Do
NOT add WDAQ_VB.BAS and WDAQR_VB.BAS to the same project.
In Visual Basic, function declarations have scope globally throughout the project. In
other words, you can define your prototypes in any module. The functions will be
recognized even in other modules.
Example Programs
You can find a set of example programs and the necessary header files in the
NIDAQWIN\VB_EX directory.
Special Considerations
Buffer Allocation
Visual Basic is quite restrictive when allocating memory. You allocate memory by declaring an
array of whatever data type with which you want to work. Visual Basic supports dynamic
memory allocation by allowing you to redimension an array to a variable size during run-time.
However, arrays are restricted to being less than 64 KB in total size (this translates to about
32,767 integers, 16,384 long integers, or 8,191 doubles). To break the 64 KB buffer size barrier,
you can use NI-DAQ memory management functions, with which you can use buffers larger
than 64 KB.
Pay special attention to NI-DAQ routines that modify string buffers, such as the
DAQ_DB_StrTransfer routine. You must ensure that the memory buffer is already allocated
to a size large enough to accommodate all of the requested samples. The following example
code copies a string buffer to disk:
:
open "filename.dat" for Binary As fh%
strBuffer$ = String$ (numSamples, 0) 'Allocate space for half
buff
:
daqErr% = DAQ_DB_StrTransfer (board%, strBuffer$, ptsTfr&,
status%)