I have just purchased the K8055 USB experiment board - looks good and should do the things I want, but does anyone have any experiance in using VBA to controll and access the inputs/outputs from packages such as Excell, Word - (Office in general)
There seem to be no examples.
I made here one.
Type the card number to cell C1.
Click Button 1 to connect the card.
Click Button 2 to read the analog input channel #1 to cell A3.
Click Button 3 to output the value in cell A4 to analog output channel #1.
[code]Option Explicit
Private Declare Sub Version Lib “k8055d.dll” ()
Private Declare Function SearchDevices Lib “k8055d.dll” () As Long
Private Declare Function SetCurrentDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib “k8055d.dll” ()
Private Declare Function ReadAnalogChannel Lib “k8055d.dll” (ByVal Channel As Long) As Long
Private Declare Sub ReadAllAnalog Lib “k8055d.dll” (Data1 As Long, Data2 As Long)
Private Declare Sub OutputAnalogChannel Lib “k8055d.dll” (ByVal Channel As Long, ByVal Data As Long)
Private Declare Sub OutputAllAnalog Lib “k8055d.dll” (ByVal Data1 As Long, ByVal Data2 As Long)
Private Declare Sub ClearAnalogChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Sub SetAllAnalog Lib “k8055d.dll” ()
Private Declare Sub ClearAllAnalog Lib “k8055d.dll” ()
Private Declare Sub SetAnalogChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Sub WriteAllDigital Lib “k8055d.dll” (ByVal Data As Long)
Private Declare Sub ClearDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Sub ClearAllDigital Lib “k8055d.dll” ()
Private Declare Sub SetDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Sub SetAllDigital Lib “k8055d.dll” ()
Private Declare Function ReadDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long) As Boolean
Private Declare Function ReadAllDigital Lib “k8055d.dll” () As Long
Private Declare Function ReadCounter Lib “k8055d.dll” (ByVal CounterNr As Long) As Long
Private Declare Sub ResetCounter Lib “k8055d.dll” (ByVal CounterNr As Long)
Private Declare Sub SetCounterDebounceTime Lib “k8055d.dll” (ByVal CounterNr As Long, ByVal DebounceTime As Long)
Sub Button1_Click()
Dim CardAddress As Long
Dim h As Long
CardAddress = ActiveSheet.Cells(1, 3).Value
h = OpenDevice(CardAddress)
Select Case h
Case 0, 1, 2, 3
ActiveSheet.Cells(1, 1) = “Card " + Str(h) + " connected”
Case -1
ActiveSheet.Cells(1, 1) = “Card " + Str(CardAddress) + " not found”
End Select
End Sub
Sub Button2_Click()
ActiveSheet.Cells(3, 1).Value = ReadAnalogChannel(1)
End Sub
Sub Button3_Click()
OutputAnalogChannel 1, ActiveSheet.Cells(4, 1)
End Sub[/code]
Thanks for the code example, much appreciated - have created the sheet and works well, you know scatching your head works some times but it so much easier having someone who knows their stuff - thanks again I think I can adapt it now, but will post again if have difficulty.