Re: Troubleshooting error in VB 6.0

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thank you for the informative response.

I do understand the error 94 and the reason it is being thrown. The problem
is it isn't consistent. For example, when the error is thrown and the user
clicks "OK" they have been instructed to delete the transaction they were
entering and re-enter it. When it is re-entered no error is thrown and the
information is saved correctly. Nothing changes from one entry to the next.
the error is random and at some locations it is more prevalent than others.
I will have to look at how the error handlers are organized and written more
closely to ensure that when the actual code causing the error is executed it
is being trapped. To compound the problem and difficulty resolving it, I
place a call to write a line of text to the test file before the saving of
the data and after the saving of the data. Then a few more lines of code
are executed, none of which are writing to the database. That is when the
error happens.

WB

"MikeD" <nobody@xxxxxxxxxxx> wrote in message
news:%23H1DhaECHHA.4348@xxxxxxxxxxxxxxxxxxxxxxx

"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



.



Relevant Pages

  • Re: Troubleshooting error in VB 6.0
    ... 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. ... Private Sub ShowRemainder(ByVal Divisor As Long, ByVal Dividend As Long) ...
    (microsoft.public.vb.general.discussion)
  • Re: Trim() function chain-link. Please Help me...
    ... Private Sub CommandButton1_Click ... Dim Divisor As Long ... Dim Pwd As String ... 'Tell the workers to not leave these 2 options blank ...
    (microsoft.public.excel.programming)
  • SoapServerException
    ... I'm trying to consume the GetAttachments of the Site Web Service, ... getting an Microsoft.SharePoint.SoapServer.SoapServerException thrown. ... foreach (string str in strAttach) ... Exception of type Microsoft.SharePoint.SoapServer.SoapServerException was ...
    (microsoft.public.sharepoint.portalserver.development)
  • Re: StackOverflowexception
    ... The system.stackoverflowexception was thrown. ... Public Shared Function GetNumofPeoplePerTrxn(ByVal OrderID As String, ... and the item.NumPersonsOnTrxn is an Integer property define in a class ... GetNumofPeoplePerTrxn(orderID, sProduct) return 2 in watch window, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: XMLEncoder problem
    ... An expected exception was thrown ... private String definition; ... though in direct opposition to the direction of the court. ...
    (comp.lang.java.programmer)