Visual Basic, VB6, VBA for UD - Windows | LabJack
« Close

Datasheets and User Guides

App Notes

Software & Driver


Visual Basic, VB6, VBA for UD - Windows

Visual Basic module and examples for the Windows UD library. The Windows UD library is the high-level Windows library/driver for the LabJack U3, U6 and UE9. For other LabJack devices, go to the Software page.

The examples are VB6 projects and VBA Excel spreadsheets. For VB .NET, we recommend our DotNet archive.

Note to VBA Users: The VB6 examples demonstrate additional UD library usage. VB6 code can be used in VBA, so take a look at the VB6 example as well. The VB6 example's .frm file contains the source code and can be opened in any text editor.

64-bit Compatibility: The PtrSafe keyword is required on function declarations to allow 64-bit compatibility. The PtrSafe keyword is not valid in older VBA versions, so our main example package does not include this keyword on declarations. To add 64-bit compatibility, please replace the LabJackUD_VB.bas file in your example package with the file downloaded by clicking here.


UD Examples Overview (Referencable)

UD Library Overview

First read the general overview of the UD library:

The UD driver has a handful of functions, many with the same 4 to 6 parameters.


The main functions are used to build a list of requests (Add), execute the list (Go), and read the result of each request (Get).  Some functions (e.g. eGet) combine a single add/go/get into one function call.


The parameters are described at the bottom of the Overview page.  The meaning of each parameter should be apparent (e.g. Channel is the channel number you are operating on), but when it is not the pseudocode section of the device's datasheet has the extra information needed.

  • Handle:  Always the handle.
  • IOType:  Always the IOType.
  • Channel:  If something besides a channel number the pseudocode section will tell you.
  • Value:  Always the value.
  • X1:  Usually not used, but if used the pseudocode section will tell you.
  • UserData:  Usually not used, but if used the pseudocode section will tell you.


Device specific pseudocode can be found in datasheet section 4.3:



Revised January 4, 2011 to add an I2C example under "All Devices"



I'm starting for the first time to program a U3.

I want to use Visual Basic 2010.

Do you have sample codes to start doing my first program, how to include or declare in my project the HEader file for VB.





If you are using Visual Basic 2010 than you would be doing everything in VB.NET.  In that case it is better to use our .NET examples, which contain examples for VB.NET.  It can be found here.

thank u

i will be Grateful if you help  me  with  using the  Frequency Output (Mode 7)  in 


For VB.NET you should use our .NET download which can be found here:

In the examples folder there for each of the LabJackUD devices (U3, U6, UE9) you should be able to find a VB.NET TimerCounter example that should provide a starting place.

it didnt take about this type of timer

and i need it very much

i use the other type of time but i need this one

thanks for answer

Sorry about the delay.  Our notification system had a problem and we just found this comment now.

The frequency output mode is similar to the other output modes.  The frequency you get is based on clock base, clock divisor, and timer value, so enable the timer and specify those 3 values.  Try it and if you have trouble post a code snippet for us to look at.  Send the code snippet to [email protected], post on our forum, or post a comment on the page for that timer mode:

Also, it is useful to practice using the test panel in LJControlPanel.

I am trying to communicate with a I2C DAC using VBA (Excel 2002) and a UE9.

I can see that 4 bytes are sent on SDA/SCL as expected. The problem is that the 3rd and 4th bytes are always sent as 0 rather than 85 as I requested.

Any help would be appreciated.

The code fragment responsible...

    Dim numWrite As Double

    Dim darray(16) As Long

    numWrite = 1

    darray(0) = 89 ' &H59

    darray(1) = 85 ' &H55

    darray(2) = 85 ' &H55

    lngError = AddRequest_ByRef(lngHandle, LJ_ioI2C_COMMUNICATION, LJ_chI2C_WRITE, numWrite, darray(0), 0)

    If lngError <> 0 Then Err.Raise lngError

    'Execute the requests.

    lngError = GoOne(lngHandle)

    If lngError <> 0 Then Err.Raise lngError

Make sure you have current firmware and the current UD driver.  Please send your xls file to [email protected] so we can check it out.

Also, if you haven't done so already take a look at the I²C example pseudocode for documentation and configuration help:

OK, so I got the I2c working by dim'ing the array as type Byte...

Dim darray(0 To 256) As Byte 

I have a new problem. I want to do an I2C read, but Excel crashes at the GoOne command every time. I have sent the excel file to your email.

   'read the current channel EEPROM volts...

    I2CAddress = &HC1

    darray(0) = &H79

    lngError = AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chI2C_ADDRESS_BYTE, I2CAddress, 0, 0)

    If lngError <> 0 Then Err.Raise lngError

    numRead = 3

    lngError = AddRequest(lngHandle, LJ_ioI2C_COMMUNICATION, LJ_chI2C_READ, numRead, darray(0), 0)

    If lngError <> 0 Then Err.Raise lngError

    'Execute the requests.

    lngError = GoOne(lngHandle)

    If lngError <> 0 Then Err.Raise lngError

The VB6 programming language installs and runs on the Windows 10 technical preview