I2C SPI USB CAN eSPI Cable Testing View All Videos Quick Start Guides Software Downloads App Notes White Papers User Manuals Knowledge Base Sales Support About Us
Products Blog Sales Support Contact Search
How Do I Pass Data Arrays using VBA with the Aardvark I2C/SPI Host Adapter?
Rena Ayeras

Question from the Customer:

I am using the Aardvark I2C/SPI Host Adapter with an Excel VBA (32-bit Excel) script. I have questions about using the function aa_i2c_read for data arrays:

If I have the array of data_in defined in Integer type (i.e. Dim data(512) As Integer), would I have the problem to pass my data array of Integer type to ByRef data_in() As Byte defined in the function?

  • For reading: Public Function aa_i2c_read (ByVal aardvark As Long, ByVal slave_addr As Integer, ByVal flags As Long, ByVal num_bytes As Integer, ByRef data_in() As Byte) as Long
  • For writing: Public Function aa_i2c_write (ByVal aardvark As Long, ByVal slave_addr As Integer, ByVal flags As Long, ByVal num_bytes As Integer, ByRef data_out() As Byte) as Long
Response from Technical Support:

Thanks for your question!  The VB6 aardvark.dll can be directly used, as it uses the same data as VBA. For more information, please refer to this article about data types in VBA and .NET.

VBA Script for Integer Type

Note: This example was created for 32-bit Excel; 32-bit Aardvark VB6 DLL was used.

Private Declare Function vb6_aa_find_devices Lib "C:\User\Downloads\aardvark-api-windows-i686-v5.15\aardvark-api-windows-i686-v5.15\vb6\aardvark.dll" (ByVal num_devices As Long, ByRef devices As Integer) As Long

Sub Button2_Click()

Dim num As Long

Dim devices(15) As Integer

Dim nelem As Long

num = vb6_aa_find_devices(16, devices(0))

End If

End Sub

Additional Code Examples

There are more code examples in the VB6 folder. These 32-bit Aardvark API scripts can be used as-is or modified for your specifications. This folder also has a VBA example that is equivalent to aalights.c, which integrates VB6 dll with VBA. This example uses the I2C/SPI Activity Board. The GPIO lights on the Activity Board flash when you click Button 1 in the Excel sheet.

Example of using VBA to create a button on Excel VBA Excel Start Button

You can see the VBA code behind the button click event. To do so, right-click the Button 1 on the Excel sheet, and then Select Assign Macro and Edit.

We hope this answers your questions. Additional resources that you may find helpful include the following:

If you want more information, feel free to contact us with your questions, or request a demo that applies to your application.