Results 1 to 8 of 8

Thread: Run-time Error 5 ????

  1. #1

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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.

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Can you post the code for RoundUp() too ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Try using Doubles instead of Integers.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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:
    1. Private Function RoundUp(NumberArg As Double) As Double
    2.     If ((NumberArg * varFuelBurnRate / 60) - Int(NumberArg) * varFuelBurnRate / 60) > 0 Then
    3.         varRoundUp = Int(NumberArg * varFuelBurnRate / 60) + 1
    4.     Else
    5.         varRoundUp = (NumberArg * varFuelBurnRate / 60)
    6.     End If
    7. End Function
    8.  
    9. ' elsewhere
    10.  
    11. varRoundUp = RoundUp(555555)
    12. MsgBox varRoundUp
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  6. #6

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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.

  7. #7

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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.

  8. #8
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043

    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
  •  



Click Here to Expand Forum to Full Width