Ben niet zo heel bekend in VBA heb er enkele jaren geleden wat mee gedaan maar door tijd gebrek nooit echt mee verder gegaan.

Heb van de site van Velleman het volgende:


Option Explicit
Private Declare Function Version Lib "k8055d.dll" () As Long
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)
Private Declare Function SetTimer Lib "user32" ( _
    ByVal HWnd As Long, ByVal nIDEvent As Long, _
    ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" ( _
    ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
Dim TimerID As Long
Dim TimerSeconds As Single
Dim CardAddress As Long
Dim n As Long

Sub Button1_Click()
    Dim h As Long
    n = 0
    h = OpenDevice(0)
    If h = 0 Then
        ActiveSheet.Cells(1, 4) = "Card 0 Connected"
        TimerSeconds = 0.1 ' the timer interval is now .1 sec.
        TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
    Else
        ActiveSheet.Cells(1, 4) = "Card 0 Not Found"
    End If

End Sub

Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
    On Error Resume Next
    Dim Data1 As Long
    Dim Data2 As Long
    Dim i As Long
    ReadAllAnalog Data1, Data2
    ActiveSheet.Cells(2, 2) = Data1
    ActiveSheet.Cells(3, 2) = Data2
    WriteAllDigital n
    ActiveSheet.Cells(5, 2) = n
    n = n + 1
    i = ReadAllDigital
    ActiveSheet.Cells(7, 2) = i
End Sub

Sub Button3_Click()
    KillTimer 0&, TimerID
    CloseDevice
    ActiveSheet.Cells(1, 4) = "Card 0 Closed"
End Sub

Maar nu zou ik dus graag door gebruik van de digitale ingang 1 de teller te resetten en te starten en door gebruik van 2 deze weer te stoppen.

Ben al een tijd bezig geweest maar krijg het niet voor elkaar.

Alvast bedankt

[Bericht gewijzigd door Henry S. op (0%)]