Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why can't add values from textbox inputs? 1

Status
Not open for further replies.

gulong

Technical User
Sep 10, 2001
4
CH
I am using VBA 5 in Excel to create some functions. While adding two values (0.6+0.2) from textbox input, I have 0.60.2. Apparently VBA adds them as text. However -*/ operators work fine. Can anybody help me out? Thanks a lot.
 
Textboxes are treated as text so you will need to convert them accordingly. Try something like this:
Code:
Dim r1 As Single, r2 As Single, r3 As Single

If IsNumeric(TextBox1.Text) = True Then
    r1 = CSng(TextBox1.Text)
Else
    MsgBox "Must Be a Number"
    TextBox1.SetFocus
    Exit Sub
End If

If IsNumeric(TextBox2.Text) = True Then
    r2 = CSng(TextBox2.Text)
Else
    MsgBox "Must Be a Number"
    TextBox2.SetFocus
    Exit Sub
End If

r3 = r1 + r2

Msgbox r3
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top