×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to add two TextBoxes arithmetically?

How to add two TextBoxes arithmetically?

How to add two TextBoxes arithmetically?

(OP)
Hi all,

I have just started learning VBA.

I have a small problem that I hope somebody may be able to help me out.

I was wondering how you add two TextBoxes together arithmetically.

My code is like this:

TextBox4.Text = TextBox3.Text + TextBox2.Text

but when I put in the data i.e 149 + 92 instead of adding it up to an answer of 241 it comes out 14992.

is there a way of adding up numerically.

thanks

Barry.

RE: How to add two TextBoxes arithmetically?

Use the Val function

Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting

Steam Engine enthusiasts: www.essexsteam.co.uk

RE: How to add two TextBoxes arithmetically?

(OP)
Hi,

Do you mean like

TextBox4.Value = TextBox3.Value + TextBox2.Value

I tried this before hand and it returned the same result.

Thanks

Barry

RE: How to add two TextBoxes arithmetically?

If you use + on strings they are appended as you have found

You want
TextBox4 = Val(TextBox3) Val(TextBox2)
Val extracts the numeric value in the text boxes
You may also need to trap errors in case there is no numeric value in one or other text.

RE: How to add two TextBoxes arithmetically?

Oops, I meant
TextBox4 = Val(TextBox3) + Val(TextBox2)

RE: How to add two TextBoxes arithmetically?

I figured that it was reasonable to point to the actual function required and let OP use VB Help - that way at least he learns something!

Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting

Steam Engine enthusiasts: www.essexsteam.co.uk

RE: How to add two TextBoxes arithmetically?

You should spend a bit of time reading up on data types. Every type is different, occupies different memory volume, and is manipulated in different ways.

Strictly speaking, they do not intermingle. However, the "Variant" type does permit "cross-breeding."

If you're working inside Excel, you should be particularly cognizant of this. Many an error has arisen because the operator sees something as a number while the program is viewing it as text.

--------------------
Bring back the HP-15
www.hp15c.org
--------------------

RE: How to add two TextBoxes arithmetically?

I think that
      TextBox4 = 1*(TextBox3) + 1*(TextBox2)
works too.
m777182

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources