Codeing problem

Ok i found some time at work to get a bit further and start to get my head around loops.
I have came up with this

Private Sub Roofmode_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Roofmode.CheckedChanged
Do
If Roofmode.Checked = True And ReadDigitalChannel(1) = True Then SetDigitalChannel(3) Else ClearDigitalChannel(3)
If Roofmode.Checked = True And ReadDigitalChannel(1) = True Then SetDigitalChannel(4) Else ClearDigitalChannel(4)
If Roofmode.Checked = False Or ReadDigitalChannel(1) = False Then ClearDigitalChannel(3)
If Roofmode.Checked = False Or ReadDigitalChannel(1) = False Then ClearDigitalChannel(4)

    Loop
End Sub

Problem is that is crashs the program if i try to uncheck the roofmode.
I did try adding a do until readdigitalchannel (1) = false OR Roofmode = False
but that had the same problem

You can use a timer instead of a loop:

[code] Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
If Roofmode.Checked = True And ReadDigitalChannel(1) = True Then SetDigitalChannel(3) Else ClearDigitalChannel(3)
If Roofmode.Checked = True And ReadDigitalChannel(1) = True Then SetDigitalChannel(4) Else ClearDigitalChannel(4)
If Roofmode.Checked = False Or ReadDigitalChannel(1) = False Then ClearDigitalChannel(3)
If Roofmode.Checked = False Or ReadDigitalChannel(1) = False Then ClearDigitalChannel(4)
End Sub

Private Sub Roofmode_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Roofmode.CheckedChanged

End Sub   [/code] 

Use timer interval 50ms to detect also short button press.
Remember also enable the timer.

That worked a treat. Thanks