|
-
Nov 20th, 2003, 11:25 AM
#1
Thread Starter
Hyperactive Member
Trap Type-Mismatch Error - Resolved
Guys,
I am having a problem trapping an error and VB error handling is not helping me out at all.
I have the computer connected to a device located on the comm port. It is sending information back to the computer. Occasionally, the device sending data sends back garbage and the vb program crashes.
I have a sub that is basically like so
VB Code:
On Error Goto errHandler
Select Case Message
Case 'blah'
Case 'blah blah'
End Select
Exit Sub
errHandler:
end sub
It all works fine until I get an extra charicter or a bit flips over the commport. I have a line in the Case statement that looks for certain values and then converts them to normal numbers so a person can read them
so I have this
VB Code:
IsNumeric(CInt("&H" & tempCommand))
If tempCommand comes in like "1E" then all is good
If it comes in like "1R", I get a type mismatch error.
Why wont this go to the errHandler?
Jerel
Last edited by Phenglai; Nov 20th, 2003 at 01:38 PM.
-
Nov 20th, 2003, 12:13 PM
#2
Member
When you run a program within the VB6 IDE.. i.e. you are DEBUGGING it.. then errors ALWAYS cause an error message, and the choice "End " or "Debug"
In the real program you will NOT see this message, nor the error.
SO how do you know that the error handler is good? (how to debug an error handler?) well.. if you are single stepping your program with F8 it behaves as though it is not being debugged.. so you can see that your error code is working..
try it!
put a breakpoint before the code that makes an error.. send some bad characters to it.. it will break at the breakpoint, not the error.. now press F8 over and over again to step your code.. you see the error handler work
-
Nov 20th, 2003, 12:26 PM
#3
actually cjard that isn't strictly true... you can set how it works: right-click in a code window, select "Toggle", and you get three options:
"Break on all errors" - act as you say (every error give a message)
"Break in class module" - act as though the program is running (any error handlers will run)
"Break on unhandled errors" - erm.. not entirely sure (and no help on this pc)
from the sounds of it, setting "Break in class module" would be the best idea (or F8 to see it in action step-by-step).
-
Nov 20th, 2003, 12:55 PM
#4
Right, this problem will occur if you have break on all errors set and are running under the debugger, but I don't believe that is the default value, and seems like a pretty weird choice to me, since it makes testing pretty bizarre.
If you do have that option set, that's your problem. However, if you don't have it set, you might try a (slow) routine that would confirm that the number can be interpreted correctly.
-
Nov 20th, 2003, 01:11 PM
#5
Phenglai: Something else must be going on because the following does go to the error handler.
VB Code:
Private Sub Form_Load()
On Error GoTo ErrorRoutine
Const VAL As String = "1R"
If IsNumeric(CInt("&H" & VAL)) Then
MsgBox "OK"
End If
Exit Sub
ErrorRoutine:
MsgBox Err.Description
End Sub
-
Nov 20th, 2003, 01:37 PM
#6
Thread Starter
Hyperactive Member
Guys,
Thanks for your help.
Martin, I tried your code first in a seperate project just to see if it worked and it did not. It never made it to the error handler.
So I did a little research based on what si-the-geek stated. I have changed the IDE to break on unhandled errors. This way it will only break when I an running in the IDE when there is an error and no error handler to catch it.
I re-ran you code Martin and it worked like it should.
I never even knew that option was there. I have been programming in VB 6.0 since 99 and never even knew it existed. Its amazing how you can work with something and still never know all of it. Anyway, I probably should have known that.
Thanks alot guys, I will try to do some more testing to make sure my code will make the fixes now in the error handler routine.
Thanks,
Jerel
-
Nov 20th, 2003, 02:19 PM
#7
Member
Originally posted by si_the_geek
actually cjard that isn't strictly true... you can set how it works: right-click in a code window, select "Toggle", and you get three options:
"Break on all errors" - act as you say (every error give a message)
"Break in class module" - act as though the program is running (any error handlers will run)
"Break on unhandled errors" - erm.. not entirely sure (and no help on this pc)
from the sounds of it, setting "Break in class module" would be the best idea (or F8 to see it in action step-by-step).
thanks for the info si.. i posted the info i gave, after asking the senior vb developer here to answer the question.. no offence to the guy, but his english isnt as strong as a native person's so theres only so much detail i can put across before he gets confused: ) (he started telling me how to Shell Execute, when i first asked him if there was a difference between starting a program from within the ide and starting a program from windows..)
-
Nov 21st, 2003, 04:50 AM
#8
no worries folks, we all miss out something every now and then... lets face it there's lots of options to fiddle with
I'm glad I learnt this one a long time ago!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|