math function - division

.net , vb6 United States
  • 18 years ago

    I need to be able to divide by zero.  Right now I have declared the variable as Double but I keep getting an run time error.  division by zero.  

  • 18 years ago


    Tut, tut, tut. Someone hasn't learnt maths yet. The whole number system decides that dividing by zero is impossible.


    I you want to return zero when dividing by zero, what you do is:

    Code:
    On Error Goto DivByZero
    <Stick your little attempt to do the impossible here>
    DivByZero:
    <that variable> = 0
    On Error Goto 0

  • 18 years ago

    Quote:
    I you want to return zero when dividing by zero

    You can't return 0 when x/0 !!!!


    The correct way to handle this problem is to use instead of 0 very small (positive?) numbers.(double type variable)
    Anyway the answer is specific  to the problem when need to divide by 0.


    ...this is my opinion...



    Xcuse my english..

  • 18 years ago

    I can't begin to imagine why you'd want to divide by zero in the first place.


  • 18 years ago

       On Error Resume Next
       Dim b As Integer
       
       b = a / 0
       MsgBox b



  • 18 years ago

    Hi,
            Cool of  you to desire to divide a number by zero. Frankly thats impossible so get it out of your head and think of how you can trap the said error:Division By Zero
           Try out this code:
    Dim NumZero As Integer
    On Error GoTo ErrHandler
       If txtDivideBy.Text <> Empty And txtNumber.Text <> Empty Then           txtResult.Text = CInt(txtNumber.Text) / CInt(txtDivideBy.Text)
    ErrHandler:
       If Err.Number = 11 Then 'it is division by zero
           Num
    Zero = 0
           txtResult.Text = Num_Zero
       End If

  • 18 years ago

    It is a requirement in the VB class that I'm taking.

  • 18 years ago

    Sorry but so far no way has been developed on how to divide a number by zero. Tell taht to your teacher. However if you ever come across a way through which it can be done then just let me know of it as soon as possible.

  • 18 years ago

    And as soon as he tells you how to divide a number by zero, please tell me so I can note "the day logic died" on my calendar, and then unlearn all of the mathematics I've ever been tought.


  • 18 years ago

    To do it in .NET with structured error handling :


    private function divide() as double


    dim a as double


    try
        a = a/0
    catch exc as exception
       msgbox(exc.message.tostring)
    end try
     
    end function

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” - Rick Osborne