Hi,
Is there any VBA example without .NET framework for Excel 2003?
Thanks and regards,
Don
VBA Example on Excel
Moderator: serg
Re: VBA Example on Excel
Hi Don,
Our VBA sample for MS Excel doesn't use the .NET framework directly. Instead, VBA is using the SUB-20 as a regular COM/ActiveX control. You have to generate the sub20dnc.tlb file for VBA/VB6 though. See the SUB-20 .NET document for details.
In general, if you know how to use a regular windows dll from your VBA-capable document you can directly call the sub20.dll - the SUB-20 main interface library
Regards
Our VBA sample for MS Excel doesn't use the .NET framework directly. Instead, VBA is using the SUB-20 as a regular COM/ActiveX control. You have to generate the sub20dnc.tlb file for VBA/VB6 though. See the SUB-20 .NET document for details.
In general, if you know how to use a regular windows dll from your VBA-capable document you can directly call the sub20.dll - the SUB-20 main interface library
Regards
Re: VBA Example on Excel
Hi,
I try to follow user menu to define data type of SlavesArry in Excel VBA,but system show me the error message”Data Type not match”.I don't know how to define data type of SlavesArry in Excel VBA.Help!
Example in sub20net user menu as following
Private Sub I2CEnumSlaves()
Dim Dev As New Sub20
Dim SlavesArry(127) As Byte
Dim SlaveCntr As Integer
' Open SUB-20 device
If Not Dev.Open(0) Then
GoTo Done
End If
' Set I2C clock frequency to 400kHz
If Not Dev.I2C_SetFrequency(400000) Then
GoTo Done
End If
' Scan I2C bus for slaves
If Not Dev.I2C_Scan(SlavesArry, SlaveCntr) Then
GoTo Done
End If
If SlaveCntr > 0 Then
For i = 0 To SlaveCntr - 1
' Adding all the slaves to a list
AddToList(SlavesArry(i).ToString()
Next
End If
Done:
If Dev.GetLastError() > 0 Then
MsgBox(Dev.GetStrError(Dev.GetLastError()))
End If
' Close SUB-20 device
Dev.Close()
End Sub
End Sub
I try to follow user menu to define data type of SlavesArry in Excel VBA,but system show me the error message”Data Type not match”.I don't know how to define data type of SlavesArry in Excel VBA.Help!
Example in sub20net user menu as following
Private Sub I2CEnumSlaves()
Dim Dev As New Sub20
Dim SlavesArry(127) As Byte
Dim SlaveCntr As Integer
' Open SUB-20 device
If Not Dev.Open(0) Then
GoTo Done
End If
' Set I2C clock frequency to 400kHz
If Not Dev.I2C_SetFrequency(400000) Then
GoTo Done
End If
' Scan I2C bus for slaves
If Not Dev.I2C_Scan(SlavesArry, SlaveCntr) Then
GoTo Done
End If
If SlaveCntr > 0 Then
For i = 0 To SlaveCntr - 1
' Adding all the slaves to a list
AddToList(SlavesArry(i).ToString()
Next
End If
Done:
If Dev.GetLastError() > 0 Then
MsgBox(Dev.GetStrError(Dev.GetLastError()))
End If
' Close SUB-20 device
Dev.Close()
End Sub
End Sub
Re: VBA Example on Excel
The example in the document is in VB.NET. For the VBA it should be slightly modified
Private Sub I2CEnumSlaves()
Dim Dev As New Sub20
Dim SlaveCntr As Long
Dim SlavesArry As New SystemByteArray
Dim Success As Boolean
SlavesArry.CreateInstance (128)
' Open first available SUB-20 device
Success = Dev.Open(0)
If Not Success Then
GoTo Done
End If
' Set I2C clock frequency to 400kHz
Success = Dev.I2C_SetFrequency(400000)
If Not Success Then
GoTo Done
End If
' Scan I2C bus for slaves
Success = Dev.I2C_Scan(SlavesArry.GetSystemArray(), SlaveCntr)
If Not Success Then
GoTo Done
End If
If SlaveCntr > 0 Then
For i = 0 To SlaveCntr - 1
' Adding all the slaves to a list
Next
End If
Done:
If Dev.GetLastError() > 0 Then
MsgBox (Dev.GetStrError(Dev.GetLastError()))
End If
' Close SUB-20 device
Dev.Close
End Sub
Regards
Private Sub I2CEnumSlaves()
Dim Dev As New Sub20
Dim SlaveCntr As Long
Dim SlavesArry As New SystemByteArray
Dim Success As Boolean
SlavesArry.CreateInstance (128)
' Open first available SUB-20 device
Success = Dev.Open(0)
If Not Success Then
GoTo Done
End If
' Set I2C clock frequency to 400kHz
Success = Dev.I2C_SetFrequency(400000)
If Not Success Then
GoTo Done
End If
' Scan I2C bus for slaves
Success = Dev.I2C_Scan(SlavesArry.GetSystemArray(), SlaveCntr)
If Not Success Then
GoTo Done
End If
If SlaveCntr > 0 Then
For i = 0 To SlaveCntr - 1
' Adding all the slaves to a list
Next
End If
Done:
If Dev.GetLastError() > 0 Then
MsgBox (Dev.GetStrError(Dev.GetLastError()))
End If
' Close SUB-20 device
Dev.Close
End Sub
Regards
Re: VBA Example on Excel
Hi,
I'd like to send data via I2C_Write command but the result is false.Why?
Source code as below.
Dim DataArry As New SystemByteArray
DataArry.CreateInstance (16)
'Protocol : S_0xBE_W_08_3A_P
Success = DataArry.SetValue(&H8, 0)
Success = DataArry.SetValue(&H3A, 1)
Success = Dev.I2C_Write(&H5F, &H0, 0, DataArry.Array)
Thanks and regards
I'd like to send data via I2C_Write command but the result is false.Why?
Source code as below.
Dim DataArry As New SystemByteArray
DataArry.CreateInstance (16)
'Protocol : S_0xBE_W_08_3A_P
Success = DataArry.SetValue(&H8, 0)
Success = DataArry.SetValue(&H3A, 1)
Success = Dev.I2C_Write(&H5F, &H0, 0, DataArry.Array)
Thanks and regards
Re: VBA Example on Excel
Hi,
You can get extended I2C status code by calling the I2C_GetStatus method.
See the "3.2.8 I2C Status" in the "User Manual" document for more details
Regards
You can get extended I2C status code by calling the I2C_GetStatus method.
See the "3.2.8 I2C Status" in the "User Manual" document for more details
Regards