9 Replies - 10396 Views - Last Post: 17 July 2012 - 03:30 PM Rate Topic: -----

#1 newaudrey  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 162
  • Joined: 08-July 10

why do i need to double click a button before i got the error?

Posted 14 July 2012 - 09:47 PM

this is the code for my program

i found this code in microsoft and modify it to suite my needs

Private Sub cmdconnect_Click()
On Error GoTo commErr
' Buffer to hold input string
   Dim Instring As String
   ' Use COM1.
   MSComm1.CommPort = Combo1.Text
   ' 9600 baud, no parity, 8 data, and 1 stop bit.
   MSComm1.Settings = "9600,N,8,1"
   ' Tell the control to read entire buffer when Input
   ' is used.
   MSComm1.InputLen = 0
   ' Open the port.
   MSComm1.PortOpen = True
   ' Send the attention command to the modem.
   MSComm1.Output = "ATV1Q0" & Chr$(13) ' Ensure that
   ' the modem responds with "OK".
   ' Wait for data to come back to the serial port.
   Do
      DoEvents
   buffer$ = buffer$ & MSComm1.Input
   Loop Until InStr(buffer$, "OK" & vbCrLf)
   MsgBox buffer$
commErr:
    If Err.Number = 8005 Then
        MsgBox "Port is busy"
    ElseIf Err.Number = 8002 Then
         MsgBox "Invalid Port"
    Exit Sub
    End If
End Sub


i know that the output is error 8005 but it will output the error "Port is busy" when i clicked again the button what do i need? please help me. i'm really noob

Is This A Good Question/Topic? 0
  • +

Replies To: why do i need to double click a button before i got the error?

#2 newaudrey  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 162
  • Joined: 08-July 10

Re: why do i need to double click a button before i got the error?

Posted 14 July 2012 - 11:41 PM

please help me. if i dont have error handling code and i choose the wrong port the program will just hang forever.

what i want is if the user will choose comport 1 (the communication port i think hehhe) it will say port is busy just like that or any error message


the wrong with my codes(in my upper post) is when i clicked the button once it doesn't hang or prompt a message even i wait for an hour but when i clicked it again it will prompt me the error message that the port is busy. please help me. :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#3 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 269
  • Joined: 21-May 09

Re: why do i need to double click a button before i got the error?

Posted 15 July 2012 - 10:09 AM

uumm... you already have error handler.

when you first click the button the program do whatever it should do, since it dont (probably never) finish doing it another click would raise the error message saying the port is busy.

is this code completed? do you get any message when it finish if it does finish? maybe a label or textbox show different text?

what about debugging and looking into each line and seeing what it do?

it seems this button connect. do you have any disconnect button or some other button to actually send data?
Was This Post Helpful? 0
  • +
  • -

#4 newaudrey  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 162
  • Joined: 08-July 10

Re: why do i need to double click a button before i got the error?

Posted 15 July 2012 - 04:20 PM

sir yes its complete except the auto checking of ports available in my computer.

when i don't have error handler it will just hang the program forever. what im thinking is add a code that wait for the program to at least wait for 4 seconds to respond. but i don't know the code can u guide me or give me a hint?
Was This Post Helpful? 0
  • +
  • -

#5 newaudrey  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 162
  • Joined: 08-July 10

Re: why do i need to double click a button before i got the error?

Posted 16 July 2012 - 03:31 AM

what is the error? please help me
Was This Post Helpful? 0
  • +
  • -

#6 newaudrey  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 162
  • Joined: 08-July 10

Re: why do i need to double click a button before i got the error?

Posted 16 July 2012 - 04:36 AM

please help me. how to set a time in connecting to a port?

what is the opposite of sleep function in vb6? please give me hints
Was This Post Helpful? 0
  • +
  • -

#7 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 269
  • Joined: 21-May 09

Re: why do i need to double click a button before i got the error?

Posted 16 July 2012 - 09:34 AM

no need to panic!
i work most of the day and cant answer right away. relax

it dosent seems like you have an error.

do you have a disconnect button?
if so use it and see if you get error message after you disconnect.

as for sleep function, there is no opposite to it, either use it or use a timer with interval set to 1000, that way it count in seconds
Was This Post Helpful? 0
  • +
  • -

#8 newaudrey  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 162
  • Joined: 08-July 10

Re: why do i need to double click a button before i got the error?

Posted 16 July 2012 - 03:42 PM

so what is the reason sir i need to double click it to got the error message?
Was This Post Helpful? 0
  • +
  • -

#9 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 328
  • View blog
  • Posts: 1,990
  • Joined: 26-March 09

Re: why do i need to double click a button before i got the error?

Posted 17 July 2012 - 12:01 AM

Couple of points.

1. You have no ExitSub before your error code, so it will always drop into your error handler once it's completed it's loop - not good practice.

2. I don't see anywhere that you close the port (as mentioned by Neku more than once). Either close it, or check if it's already open before opening it again!

3. To prevent your button code being executed more than once, you can adopt a couple of techniques. One is to set a Boolean variable to true to indicate that the code is executing. Test for that variable at the top of your Click event and exit if it's true. Set the variable to False on exit of the code execution. A similar technique is to disable the button (Enable property = False), to prevent it being clicked again. Set it to True on the code exit.

4. To set a timeout. Add a timer control with what ever interval you require. Enable the timer in your Click event and set a Boolean variable = False (blnTimeOut = False). In the Timer event, set the Boolean variable = True (blnTimeOut = True), then use that variable in your loop.

For example (you'll need to check this - I'm doing this without VB)
Do
...
Loop Until YourCode or blnTimeOut=True

'On exiting of the loop check if it timed out or not
if blnTimeOut then
  msgbox "Timed Out"
endif


That should give you some pointers in the right direction, so please take on board some of the suggestions that have already been made by Neku and I and give them a go.

This post has been edited by maj3091: 17 July 2012 - 12:03 AM

Was This Post Helpful? 1
  • +
  • -

#10 BobRodes  Icon User is offline

  • Lovable Curmudgeon
  • member icon

Reputation: 600
  • View blog
  • Posts: 3,069
  • Joined: 19-May 09

Re: why do i need to double click a button before i got the error?

Posted 17 July 2012 - 03:30 PM

Another point. Please stop screaming hysterically for help. If you were tied to a railroad track and a train was coming, no doubt we'd drop what we're doing to help you. But you aren't. All of your negative reputation points come from this extremely annoying habit, and from people who very rarely downrate anyone. When you do this, you also make it harder for anyone else to get helpful information from your thread, because they have to read around your badgering.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1