Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   visual basic calculator divide zero error (https://www.askmehelpdesk.com/showthread.php?t=708034)

  • Oct 10, 2012, 02:21 AM
    Cherry1993
    visual basic calculator divide zero error
    Hi,

    I'm making a calculator for school and I can't seem to find the way to work it out.
    You see, I need to make sure that when someone tries to divide by zero, it shows a message saying it's not possible.
    Because right now I get an error code and after that it won't work.
    I've tried multiple options I found online and in my textbook, but it always gives an error code to me.
    This is the coding I used:

    Code:

    If plusmin = "x" Or plusmin = "X" Then
     Uitkomst.AddItem (Getal1.Text & "x" & Getal2.Text & "=" & Str(G1 * G2))
     End If
     
    If plusmin = ":" Or plusmin = "/" Then
    Uitkomst.AddItem (Getal1.Text & ":" & Getal2.Text & "=" & Str(G1 / G2))
    End If



    If plusmin = "-" Then
    Uitkomst.AddItem (Getal1.Text & "-" & Getal2.Text & "=" & Str(G1 - G2))
    End If

    If plusmin = "+" Then
    Uitkomst.AddItem (Getal1.Text & "+" & Getal2.Text & "=" & Str(G1 + G2))
    End If


    I'd really appreciate the help.
    Thank you,

    Cherry
  • Oct 10, 2012, 03:33 AM
    ScottGem
    This is fairly simple. After you test for division, you then have to test if G2 = zero.

    Alternatively you can add error trapping to test for the error code to give your own message.

  • All times are GMT -7. The time now is 10:40 PM.