Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
This Document is not yet Rated  Rate this Document

“Variable Not Defined” When Programming DAQ in Microsoft Visual Basic 6.0

Hardware: Multifunction DAQ (MIO)

Problem:
I constantly receive an error that says “Variable Not Defined” when programming NI-DAQmx in Visual Basic 6.0. I have checked the functions and their arguments and they are the same as those listed in the NI-DAQmx C Reference Help. What could be going wrong?

Solution:
The NI-DAQmx C API Visual Basic 6.0 Help states that most of the function names and arguments are identical between the C API and the Visual Basic 6.0 API. This help file then goes on to state that “The primary difference between the C API and the Visual Basic 6.0 API is the data type of function parameters.” Several of the function arguments specified for NI-DAQmx programming in C do not directly correlate to Visual Basic 6.0. If code is written strictly according to the NI-DAQmx C Reference Help, then the program will produce an error when it reaches one of these arguments. The program will interpret the faulty argument as a variable that you are trying to use that you have not defined and will produce an error.

The best way to determine which arguments do not correlate directly is to begin writing your application in Visual Basic 6.0 according to the NI-DAQmx C Reference Help. If a “Variable Not Defined” error occurs, you can use the Object Browser in Visual Basic 6.0 to search the NIDAQmxCAPI library for the correct argument.

One example of this discrepancy can be seen in the following example. The DAQmxCreateAIVoltageChan function is defined in the NI-DAQmx C Reference Help to have a “units” parameter that takes an argument of either DAQmx_Val_Volts or DAQmx_Val_FromCustomScale (as seen in the image below).


[+] Enlarge Picture


While these arguments work when used in C code, using these arguments as they are written in Visual Basic 6.0 gives the “Variable Not Defined” error. If you search the NIDAQmxCAPI library, you will see that the correct argument for Visual Basic 6.0 is DAQmx_Val_VoltageUnits1_Volts (as shown in the image below). This argument is not defined in the NI-DAQmx C Reference Help, but is included in the NIDAQmxCAPI library.


[+] Enlarge Picture



Related Links:
KnowledgeBase 39BF3M1E: NI-DAQmx Support in Visual Basic 6.0
Product-Specific Support: Measurement Studio for Visual Basic Support

Attachments:


Figure 1.JPGFigure 2.JPG


Report Date: 07/24/2006
Last Updated: 04/25/2007
Document ID: 3ZND4K9X

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit