Ask Experts Questions for FREE Help !
Ask
    Cherry1993's Avatar
    Cherry1993 Posts: 1, Reputation: 1
    New Member
     
    #1

    Oct 10, 2012, 02:21 AM
    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
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #2

    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.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

How to make divide come after addition in visual basic [ 0 Answers ]

visual basic assignment

Program of calculator in visual basic 6.0? [ 0 Answers ]

Program of calculator in visual basic 6.0?

Create calculator using visual basic [ 1 Answers ]

create calculator using visual basic

How to make a calculator in visual basic 6 [ 1 Answers ]

How to make a calculator in visual basic 6, what are the codes for it?


View more questions Search