|
-
Sep 24th, 2001, 06:01 AM
#1
Run-time Error 5 ????
Hi Guys,
I have the folowing code with what I thought had Error handling built in? However during testing, when I compile and run the app, a run-time error 5 apperars (followed by MY error msgbox) if a value grater than an 'integer' ie 555555, is entered in a filed.
I thought I was handling any Error.
My question is why does the system generate an error dialog, if I was handling it ??(obviously I wasn't doing a good enough job ).
Private Sub txtClimb_Min_LostFocus()
On Error GoTo Input_Error
varClimb_Min = txtClimb_Min.Text
varRoundUp = varClimb_Min
Call RoundUp(varRoundUp)
txtClimb_Lit = varRoundUp
Exit Sub
Input_Error:
MsgBox "Please enter a valid number", vbOKOnly + vbCritical
txtClimb_Min.SelStart = 0
txtClimb_Min.SelLength = Len(txtClimb_Min.Text)
txtClimb_Min.SetFocus
End Sub
PS. 1. The Function (Call RoundUp(varRoundUp)) has the same type error handling.
2. It ONLY happens to the compiled app, I can't trip it up running under VB?
Cheers,
Bruce (I'm still learning ).
________
Angelique
Last edited by Bruce Fox; Aug 14th, 2011 at 03:51 AM.
-
Sep 24th, 2001, 06:06 AM
#2
Retired VBF Adm1nistrator
Can you post the code for RoundUp() too ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 24th, 2001, 06:12 AM
#3
Heres the Roundup
Function RoundUp(NumberArg As Integer)
On Error GoTo Round_Error
If ((NumberArg * varFuelBurnRate / 60) - Int(NumberArg * varFuelBurnRate / 60)) _
> 0 Then
varRoundUp = Int(NumberArg * varFuelBurnRate / 60) + 1
Else
varRoundUp = (NumberArg * varFuelBurnRate / 60)
End If
Exit Function
Round_Error:
MsgBox "Please enter a valid number", vbOKOnly + vbCritical
End Function
-
Sep 24th, 2001, 06:22 AM
#4
Retired VBF Adm1nistrator
Try using Doubles instead of Integers.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 24th, 2001, 06:31 AM
#5
Retired VBF Adm1nistrator
The reason I say Doubles is because they have the largest valid numeric range. I had to guess the values for the fuel consumption rate, and Longs werent working for me.
Anyway this is the code that I'd suggest
VB Code:
Private Function RoundUp(NumberArg As Double) As Double
If ((NumberArg * varFuelBurnRate / 60) - Int(NumberArg) * varFuelBurnRate / 60) > 0 Then
varRoundUp = Int(NumberArg * varFuelBurnRate / 60) + 1
Else
varRoundUp = (NumberArg * varFuelBurnRate / 60)
End If
End Function
' elsewhere
varRoundUp = RoundUp(555555)
MsgBox varRoundUp
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 24th, 2001, 06:37 AM
#6
Thanks plenderj :)
Using Doubles worked !!!.
I too tried longs earlier before I posted, and that didn't work.
However, the Doubles do.
(Hmmmmmm VB)
Thanks again mate.
Bruce 
________
Live Sex
Last edited by Bruce Fox; Aug 14th, 2011 at 03:51 AM.
-
Sep 24th, 2001, 07:22 AM
#7
Dooohhhh
I think the run-time error was due to the returned (from the call) value being decimal, and the varxxxx being integers/longs!
Hence the varxxxx needed to be capable of holding decimal values.
Hindsight, what a wonderfull thing it is 
Bruce.
________
SugarBaby
Last edited by Bruce Fox; Aug 14th, 2011 at 03:51 AM.
-
Sep 24th, 2001, 07:55 AM
#8
Frenzied Member
Re: Run-time Error 5 ????
Use Resume or Resume next to release error.
oh1mie/Vic
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
|