Exit a known infinite loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kvishnubhat
    New Member
    • Mar 2008
    • 4

    Exit a known infinite loop

    Hi
    I am learning VB and tried to write a code to switch on the relay and switch off the relay using com port. Every thing went perfect and now i am stuck up in a event, by clicking OFF button the relay should go on/off every 3 sec, until i press ON button.
    The sample code is

    [CODE=vb]Public Sub RELAY_Timer_Cli ck(Index1 As Integer)

    RELAY_Timer(Ind ex1).Enabled = False
    If RELAY_Timer(Ind ex1).Caption = "ON" Then
    RELAY_Timer(Ind ex1).Caption = "OFF"
    RELAY_Timer(Ind ex1).Enabled = True
    Form1.MSComm1.O utput = Chr$(254) 'Enter Command Mode
    Form1.MSComm1.O utput = Chr$(Index1) 'Turn Relay Off
    Else
    RELAY_Timer(Ind ex1).Caption = "ON"
    RELAY_Timer(Ind ex1).Enabled = True
    While True
    Form1.MSComm1.O utput = Chr$(254) 'Enter Command Mode
    Form1.MSComm1.O utput = Chr$(Index1 + 8) 'Turn Relay Off
    Sleep (3000)
    Form1.MSComm1.O utput = Chr$(254) 'Enter Command Mode
    Form1.MSComm1.O utput = Chr$(Index1)
    Sleep (3000)
    If RELAY_Timer(Ind ex1).Caption = "ON" Then Exit Sub
    Wend

    End If
    Form1.GetData
    Form1.Read_All_ Click


    End Sub[/CODE]
    Please help in resolving the code
    Last edited by Killer42; Mar 17 '08, 07:01 AM. Reason: Added CODE=vb tag
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Do you know for a fact that it is definitely the While loop which is holding things up? Have you traced the execution and checked what happens when it should exit the loop?

    Also, what version of VB is this? (My guess would be VB6, from the syntax.)

    Comment

    Working...