IDIV - divide be zero: error handling

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djklocek
    New Member
    • Aug 2006
    • 5

    IDIV - divide be zero: error handling

    Hello.
    I've got a problem. My software crashes and maybe it's because IDIV instruction - division by 0. Please help me how to handle it in VB6 (check value before dividing) . I found articles on that but only Java and C++ and nothing about VB6.
    Best regards
    Edit/Delete Message
  • Hemant Pathak
    Recognized Expert New Member
    • Jul 2006
    • 92

    #2
    Hi............. .
    First check ur datatype if Datatype is String then simly check
    if VariableName="0 " then
    otherwise
    if VaribleName=0 then

    thats all

    if it is not working then send me us Validation Code i will try..........
    at this email address..
    pathak.pathak@g mail.com

    Comment

    • sashi
      Recognized Expert Top Contributor
      • Jun 2006
      • 1749

      #3
      Hi there,

      This is when error handling comes handy, please refer to below code segment, hope it helps to solve your problem.. take care my fren.. :)

      Division by Zero generates error number 6, which means you need to trap this error number in order to prevent your application from crashing, rite?

      Code:
      ublic Sub OnErrorDemo()
         On Error GoTo ErrorHandler   ' Enable error-handling routine.
         Dim x As Integer = 32
         Dim y As Integer = 0
         Dim z As Integer
         z = x / y   ' Creates a divide by zero error
         On Error GoTo 0   ' Turn off error trapping.
         On Error Resume Next   ' Defer error trapping.
         z = x / y   ' Creates a divide by zero error again
         If Err.Number = 6 Then
            ' Tell user what happened. Then clear the Err object.
            Dim Msg As String
            Msg = "There was an error attempting to divide by zero!"
            MsgBox(Msg, , "Divide by zero error")
            Err.Clear() ' Clear Err object fields.
         End If
      Exit Sub      ' Exit to avoid handler.
      ErrorHandler:  ' Error-handling routine.
         Select Case Err.Number   ' Evaluate error number.
            Case 6   ' Divide by zero error
               MsgBox("You attempted to divide by zero!")
               ' Insert code to handle this error
            Case Else
               ' Insert code to handle other situations here...
         End Select
         Resume Next  ' Resume execution at same line
                      ' that caused the error.
      End Sub

      Comment

      • djklocek
        New Member
        • Aug 2006
        • 5

        #4
        Hello.

        My error is internal error - I cannot trap it inside VB because whole VB crashes. Thank you for your help but this time simple error handler can't do the job.
        Best regards

        Comment

        • sashi
          Recognized Expert Top Contributor
          • Jun 2006
          • 1749

          #5
          Hi there,

          if this type error handler is not good enough to trap error, then i don't know on how to help you.. take care my fren..

          Comment

          • strapping
            New Member
            • Sep 2006
            • 1

            #6
            Hi!
            I heave almost the same problem! but my Msg Error is the 11th, I have some Textboxes and I did a division between those controls!

            ex: Text3= Val( Text1* 1000) / Val(Text2)
            but Text2=0
            is not a string datatype, I made my DB in Access and the Dtype was Numeric
            Int so I don't know whats going on!!!!

            Please help with these problem!!!
            Thanks

            Comment

            Working...