Results 1 to 2 of 2

Thread: Can anyone modify Do Loop?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    Indiana,PA,USA
    Posts
    217

    Can anyone modify Do Loop?

    Hi I have a timer starting from 0 with Interval 1000 when I press command button.I need to modify this do loop to see if it has If InStr(Instring, vbCr) Then exit Do Loop if it didn't get response wait for 30 seconds and exit from the loop.Can any one modify this Do Loop to satisy both conditions please?

    Private Sub Command1_Click()
    On Error GoTo Message
    Dim Instring As String

    StartTiming
    frmTerminal.MSComm1.InputLen = 0


    frmTerminal.MSComm1.Output = "1;1;CLOSE" & Chr$(13)
    If Err Then Exit Sub

    Do
    Instring = Instring & frmTerminal.MSComm1.Input
    DoEvents

    If InStr(Instring, vbCr) Then
    Exit Do
    End If
    Loop

    DoEvents
    'MsgBox "Closing:" & Instring
    Text1.ForeColor = &HFF0000
    Text1.Text = Instring

    Exit Sub
    Message:
    MsgBox Err & " " & Error
    End Sub

    Thanks
    Sudha

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898
    Hi,

    Your code is fundementally wrong. You should be using the mscomm controls oncomm event and have your string value in the

    Case comEvReceive

    event.

    This is the only way you can reliably make sure you dont miss characters coming down the comm Port. Also make sure your thresholds are set to the right number so that you dont end up with buffer overflow.

    Check out the online help cor all the oncomm events. They do work.

    Regards
    Bill Crawley

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width