[RESOLVED] Calculator Addition Not Working
Hey guys, I'm pretty bored and figured I'de make a calculator for my homework and everything. Well I've got subtraction, division, multiplication , etc working, but when I do add it adds the numbers togethor
so, If I add 5 + 4 it equals 54.
If I add 7+2 it equals 72. Everything else works fine. Can anyone tell me what I'm doing wrong?
Code:
If addbutton Then
equalbox.Text = onebox.Text + twobox.Text
End If
Re: Calculator Addition Not Working
::EDIT::
I'm sorry , You can easily fix the problem by doing the following.
Code:
Dim first As Double
Dim second As Double
first = onebox.Text
second = twobox.Text
If addbutton.Checked Then
equalbox.Text = first + second
End If
Re: [RESOLVED] Calculator Addition Not Working
The + operator is overloaded... when one of the operands is a string concatenation is performed instead of addition. Post #2 code relies on implicit conversion for storage into double variables. Explicit conversion is performed as follows:
equalbox.Text = CDbl(onebox.Text) + CDbl(twobox.Text)
You will also need to place text validation and/or error handling, otherwise conversion will throw an error if value is non-numeric (or cannot be converted to a numeric value).