StepperMotor.frm
Private Sub Form_Load()
Clockwise.Text = "0": CounterClockwise.Text = "0"
End Sub

Private Sub Clockwise_KeyPress(KeyAscii%)
If KeyAscii = 13 Then Call SendClockwiseCommand ' Wait until a value is entered
If (KeyAscii < Asc("0")) Or (KeyAscii > Asc("9")) Then KeyAscii = 0 ' Only accept digits
End Sub

Private Sub CounterClockwise_KeyPress(KeyAscii%)
If KeyAscii = 13 Then Call SendCounterClockwiseCommand ' Wait until a value is entered
If (KeyAscii < Asc("0")) Or (KeyAscii > Asc("9")) Then KeyAscii = 0 ' Only accept digits
End Sub

Private Sub SendClockwiseCommand()
Dim Buffer(2) As Byte
' Need to send a turn command to the IO device
Counter% = Val(Clockwise.Text): CounterClockwise.Text = "0"
Buffer(0) = 0 ' Clockwise command
Buffer(1) = Counter% And &HFF: Buffer(2) = ((Counter% And &HFF00) / 16) And &HFF
Call WriteUSBdevice(AddressFor(Buffer(0)), 3)
End Sub

Private Sub SendCounterClockwiseCommand()
Dim Buffer(2) As Byte
' Need to send a turn command to the IO device
Counter% = Val(CounterClockwise.Text): Clockwise.Text = "0"
Buffer(0) = 1 ' CounterClockwise command
Buffer(1) = Counter% And &HFF: Buffer(2) = ((Counter% And &HFF00) / 16) And &HFF
Call WriteUSBdevice(AddressFor(Buffer(0)), 3)
End Sub