Click to See Complete Forum and Search --> : Com Program Freezing


Catrina
February 17th, 2000, 07:25 AM
I am trying to convert an old DOS dialup
communications program to windows.

The program dials the number (I left it out, didn't want to post it on
the web), then sends out 6s until it receives a 7 from the receiving end.
I added text boxes just to see if the program was working. At first it
timed out too quickly, so we made a few changes, now it dials and connects,
but then freezes my computer. I have to CTRL ALT Delete to get out.
Here is the code. Can you see a reason for the freezing. Next I will be
adding the code to send a password, then extract the files from the sending end and transmit
them. Any help for this problem and advice for the next step will be great appreciated!


Private Sub Command1_Click()
MSComm1.CommPort = 2
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True
MSComm1.Output = "ATDT Number" & vbCr
MSComm1.InputLen = 1

WaitForInput:
If MSComm1.InBufferCount = 0 Then
GoTo WaitForInput
End If

C$ = MSComm1.Input
If C$ = Chr$(10) Then GoTo WaitForInput
If C$ = Chr$(13) Then GoTo TestConnect
P$ = P$ + C$
Text2.Text = P$
GoTo WaitForInput

TestConnect:
Text2.Text = P$
If InStr(P$, "CONNECT") Then GoTo 22175
P$ = ""
GoTo WaitForInput




22175 For A! = 1 To 100000
If MSComm1.InBufferCount = 0 Then GoTo 22201
A! = 1
C$ = MSComm1.Input
If C$ = Chr$(13) Then COUNTS% = COUNTS% + 1
If COUNTS% = 50 Then GoTo 22161

22200 If C$ = Chr$(7) Then GoTo 22204
22201 MSComm1.Output = (Chr$(6) & Chr$(13))

Next A!
Text1.Text = "Timeout"
GoTo 22175
22204 Text1.Text = "Works!"
Exit Sub
22161 Text1.Text = "Errors"

End Sub



Private Sub Exit_Click()
End
End Sub

Cakkie
February 17th, 2000, 07:42 AM
The reason your program is frrezing is probably becaus of the waitforinput: loop

you always keep returning to the same point until you get your input. This will cause your program to freeze.
My advice is to use a timer, set it to a delay of like 10 ms and do the check there. This way your app won't freeze.

Tom Cannaerts
slisse@planetinternet.be

The best way to escape a problem, is to solve it.

Kyle Burns
February 17th, 2000, 07:54 AM
You're creating an endless loop with WaitForInput...GOTO WaitForInput. You need to use the OnComm() event of the MSComm control to call your routines. Something like this:

private Sub Command1_Click()
MSComm1.CommPort = 2
'set the rest of the properties and connect
End Sub
private Sub MSComm1_OnComm()
If MSComm1.InBufferCount > 0 then
'Call Your Other Routines
End If
End Sub



GOTO is EVIL