[quote]Is it not possible to write loops for the digital channels?[/quote] No, it is not possible, the loop always freezes the Excel.
You may use timer instead.
Please see the Excel example in the latest software package for the K8055 “Complete SDK Pack (Rev 4.0)”: velleman.eu/support/download … 8055&type=
OK. Now it works.
The trick was to put “DoEvents” to the loop.
Here is the full working code.
There are now two buttons.
First button opens the card.
The second button starts LD1 to flash.
Next press stops flashing.
Option Explicit
Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib "k8055d.dll" ()
Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Long)
Private Declare Sub ClearDigitalChannel Lib "k8055d.dll" (ByVal Channel As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim i As Long
Sub Button_Open_Click()
Dim h As Long
h = OpenDevice(0)
If h = 0 Then
ActiveSheet.Cells(1, 2) = "Card 0 opened"
Else
ActiveSheet.Cells(1, 2) = "Card 0 not found"
End If
i = 0
End Sub
Sub Button2_Click()
i = i Xor 1
ActiveSheet.Cells(1, 1) = "Wait"
Do
SetDigitalChannel (1)
Sleep 100
ClearDigitalChannel (1)
Sleep 100
DoEvents
Loop Until i = 0
ActiveSheet.Cells(1, 1) = "OK"
End Sub
If you mean MS Excel, then your loop will basically continue looping and hogging CPU usage. This will mean that excel cannot redraw / refresh the window and handle user input because it is unable to process any event handlers internally.
Any code you write either needs to execute and finish quickly or make appropriate calls to handle the normal background events itself. This principle applies to any programming language and is the reason why most program loops have a small sleep / delay in them so that the system can continue to execute other background tasks.