Convert text to Long

R

Risky Dave

Hi,

I suspect that this is really easy but I haven't been able to figure out the
solution.

I have a form that holds a couple of numbers in text boxes, eg:
TextBox1.Value is 2,000
TextBox2.Value is 12,500

What I want to do is add these two as numbers and display the answer in
TexBox3.

There will be no further manipulation of the value in TextBox3, so I don't
actually care if it stored as a number or as text, so long as it is diaplayed
as 14,500

TIA

Dave

TIA
 
M

Mike H

Hi,

If the commas aren't there you can use

TextBox3.Value = Val(TextBox1.Value) + Val(TextBox2.Value)

If the commas are real use

TextBox3.Value = CLng(TextBox1.Value) + CLng(TextBox2.Value)

Mike
 
M

Mike H

You wanted the comma

myval = CLng(TextBox1.Value) + CLng(TextBox2.Value)
TextBox3.Value = Left(myval, Len(myval) - 3) & "," & Right(myval, 3)

Mike
 
R

Risky Dave

Many thanks

Mike H said:
Hi,

If the commas aren't there you can use

TextBox3.Value = Val(TextBox1.Value) + Val(TextBox2.Value)

If the commas are real use

TextBox3.Value = CLng(TextBox1.Value) + CLng(TextBox2.Value)

Mike
 
R

Rick Rothstein

myval = CLng(TextBox1.Value) + CLng(TextBox2.Value)
TextBox3.Value = Left(myval, Len(myval) - 3) & "," & Right(myval, 3)

That last line can be made simpler using the Format function...

TextBox3.Value = Format(myval, "0,000")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top