Re: Troubleshooting error in VB 6.0
- From: "MikeD" <nobody@xxxxxxxxxxx>
- Date: Tue, 14 Nov 2006 18:43:22 -0500
"WB" <none> wrote in message news:eWx4oDDCHHA.3380@xxxxxxxxxxxxxxxxxxxxxxx
I have an application designed in VB6.0. I am being told from users (away
from development office) that an error is being generated (error 94). I
placed some logging code in the application to write test lines out to a
text file so I can pinpoint exactly why and where the error is happening.
The problem is the error being generated doesn't occur or match the test
lines being written to the text file. I am trying to get answer to this
question.
Error number 94 is Invalid use of Null. Chances are, you're reading data from a database into a recordset, and when going through the recordset, you're attempting to assign the field's value to a string variable or perhaps a textbox (or anything that can only accept a string).
If the data type of the FIELD is a string type, one common way of dealing with the possibility of it being null is just concatenating a 0-length string (or you can preprend it as well). Like this:
sData = oRS.Fields("MyField").Value & ""
Alternatively, use the IsNull function to check it:
If IsNull(oRS.Fields("MyField").Value Then
sData = ""
Else
sData = oRS.Fields("MyField").Value
End If
You have to use IsNull for non-string types. For example, this WON'T work:
Dim lData As Long
lData = oRS.Fields("MyField").Value & ""
(You'll get the invalid use of Null error)
Is it possible for lines of code to execute without a resume next
or any other "trapping", and the error to display after several lines have
executed beyond the actual error?
Not sure I understand the question entirely, but I guess the answer would be yes. Among others, one way you could have this situation is if you call a function that doesn't have it's own local error from a procedure which DOES have a local and active error handler. Just for an extremely simple (and admittedly poor) example:
Option Explicit
Private Sub ShowRemainder(ByVal Divisor As Long, ByVal Dividend As Long)
Dim lRemainder As Long
lRemainder = Divisor Mod Dividend
MsgBox lRemainder
End Sub
Private Sub Form_Click()
On Error GoTo EH
ShowRemainder 10, 0
'just some code that won't ever execute unless the above line is changed
'such that 0 is not passed for the Dividend parameter.
Me.Move 500, 500
EH:
MsgBox Err.Description
End Sub
(Hmm, looking at that, did I get Divisor and Dividend right? Divisor is the number "on top", right? <g>)
--
Mike
Microsoft MVP Visual Basic
.
- Follow-Ups:
- Re: Troubleshooting error in VB 6.0
- From: WB
- Re: Troubleshooting error in VB 6.0
- References:
- Troubleshooting error in VB 6.0
- From: WB
- Troubleshooting error in VB 6.0
- Prev by Date: Search A string for "###-##-######"
- Next by Date: Re: Help understanding windows shutdown process
- Previous by thread: Troubleshooting error in VB 6.0
- Next by thread: Re: Troubleshooting error in VB 6.0
- Index(es):
Relevant Pages
|