Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Reports an Overflow Error - But I Can't Duplicate It!

Status
Not open for further replies.

MrsPie

Programmer
Jul 23, 2003
20
US
I have a form with a text box collected quantity information. My user (who isn't the friendliest and thinks I'm an idiot) reported an overflow error after "typing a simple '2'" in the box. I asked for his error log, and confirmed that was the error, and it occurred somewhere in this code:

Private Sub txtUnits_KeyPress(KeyAscii As Integer)
On Error GoTo txtUnits_KeyPress_Err

If KeyAscii = vbKeyReturn Then I want to save data and close the form if they hit the Enter key
If varOp = 1 Then ' (varOp is an integer, I set it to 0, 1, or 2 depending on how the form was opened)
cmdSave_Click
Exit Sub
End If
If varOp = 2 Then ' add
cmdAdd_Click
Exit Sub
End If
End If


If kP = 0 Then (kp is an integer, I set it to 0 or 1 to let me know this is the first time they input a decimal)
If KeyAscii = 46 Then
kP = 1
Exit Sub
End If
KeyAscii = checkNumeric(True, txtUnits.Text, KeyAscii)
Else
KeyAscii = checkNumeric(True, txtUnits.Text, KeyAscii)
End If
Exit Sub


I'm stumped. I can't recreate the error and no other user has reported it, but I also can't deny the error log, which clearly ties it to this sub on this form. checkNumeric is a function borrowed from this form, used in many other places in my code without any issues.

I've tried inputting all kinds of other keys (F2, 2 without NumLock, etc.) and can't get an error. Does anyone have a clue what I'm doing wrong? Or, should I just trap for error 6 and Resume Next?

Thank you for any help!

 
A hunch says that it is a stack overflow.

From the keypress event, the program can execute cmdSave_Click or cmdAdd_Click. Have you any 'doevents' in these procedures? If your user held down the '2' key, your prog could be trying to execute a multitude of these calls.

As an asside, for the little coding required, I find it worth writing a stack log (life would be much easier if you could access the call stack in VB code), so you can see exactly what is going on - I think there is a very good example of how to do this in the "Advanced microsoft Visual basic 5" book on the MSDN Disks.

It may be worth putting in a boolean flag in your keypress event to stop multiple calls. something like:



Private Sub txtUnits_KeyPress(KeyAscii As Integer)
dim bRunning as Boolean

if bRunning then exit sub

bRunning = True

{Your code}

bRunning = False

end sub

Of course, I might be totally off on the wrong tangent...


hope this helps

SteveO

 
steveouthwaite - I appreciate any clues, whether they are the wrong tangent or not. Neither one of the two procedures called use DoEvents, but I will put in a boolean flag to stop multiple calls. I'm clueless about call stacks, but I'll check into it, thanks for the input!

I did test holding down the 2 key - I ended up with a gigantic number (technical term) and did get an overflow error, but the error number was different (he reported error number 2147217900, I got error number 2147217833). I don't know if that means anything.

Paulbent - I didn't have line numbers on the code, so I don't have the line it occurred on. The code for checkNumeric is below, but it also has error handling and I would think that if the error occurred there, that would be the module identified. By the way, this great piece of code came from this forum.

Thanks both of you, if you have any more ideas let me know!


Public Function checkNumeric(checkDecimal As Boolean, sText As String, nKey As Integer) As Integer
On Error GoTo checkNumeric_Err

'Function to check whether entered character is numeric or not
1 Dim b As Boolean
'Initially set value of b to true
2 b = True
'Checkdecimal true means that decimal can be there but only once
'and checkdecimal false means that decimal not allowed
3 If checkDecimal = True Then
'Check whether or not the given character is in "0123456789."
'if not set b to false
4 If Not InStr("0123456789.", Chr(nKey)) > 0 Then
5 b = False
6 End If
'Checking for decimal (.) second time
'if "." is already present and given character is "."
'set b to false
7 If Chr(nKey) = "." And InStr(sText, ".") Then b = False
'Check whether or not the given character is in "0123456789"
'if not set b to false
8 ElseIf checkDecimal = False Then
9 If Not InStr("0123456789", Chr(nKey)) > 0 Then
10 b = False
11 End If
12 End If
'8 is the ASCII Code for backspace
'If backspace is entered,set flag to true
13 If nKey = 8 Then b = True
'b is true means character is valid return it means enter that character,
'else return 0 which means enter nothing
14 If b Then
15 checkNumeric = nKey
16 Else
17 checkNumeric = 0
' MsgBox "Must be numeric"
18 End If

Exit Function
 
2147217833 is an ADO error: "A literal value in the command overflowed the range of the type of the associated column"

Could your end user's table be different from your development copy?

Paul Bent
Northwind IT Systems
 
paulbent - No, their table is the same as mine, and the same as all other users. I think I'm going to have to go back to the user with a new .exe with line numbers in the code to see if they get the error again.

JohnYingling - I don't know about the hours you keep, but I didn't include the code after Exit Sub. Does this make it clearer?

Private Sub txtUnits_KeyPress(KeyAscii As Integer)
On Error GoTo txtUnits_KeyPress_Err

If KeyAscii = vbKeyReturn Then
If varOp = 1 Then ' edit
cmdSave_Click
Exit Sub
End If
If varOp = 2 Then ' add
cmdAdd_Click
Exit Sub
End If
End If


If kP = 0 Then
If KeyAscii = 46 Then
kP = 1
Exit Sub
End If
KeyAscii = checkNumeric(True, txtUnits.Text, KeyAscii)
Else
KeyAscii = checkNumeric(True, txtUnits.Text, KeyAscii)
End If

Exit Sub
txtUnits_KeyPress_Err:

MsgBox "An Error Occurred " & vbCrLf & "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description & " at Line " & Erl, vbOKOnly, "Program Error"

Call GlobalErr(Err.Number, Err.Description, "txtUnits_KeyPress, Form frmDBMat on Line ", Erl)

End Sub


Thanks for your help, if anyone has any other ideas I would like to hear them!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top