PDA

View Full Version : visual basic calculator divide zero error


Cherry1993
Oct 10, 2012, 02:21 AM
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:


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

ScottGem
Oct 10, 2012, 03:33 AM
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.