ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UserForms and Variables and Types of data (https://www.excelbanter.com/excel-programming/296065-userforms-variables-types-data.html)

Larry Levinson

UserForms and Variables and Types of data
 
I have a user form with four textboxes for the user to input numbers
.... How do I tell the macro that it shoud treat the input as a number
and not as text? this is not about validation. Let's assume, just for
the sake of arguments that the user is smart enough to put in numbers
to begin with ...

thanks ...


Larry Levinson
Talking up to the vocal ...
LLevinson*Bloomberg.net
(remove the star etc ....)

Chip Pearson

UserForms and Variables and Types of data
 
Larry,

Text boxes always contain text (which may be all numbers), not
actual numeric data. Thus, you need to convert the text to a
number using a function like CInt, CLng, or CDbl. For example,

Dim N As Long
With Me.TextBox1
If IsNumeric(.Text) = True Then
N = CLng(.Text)
Else
' not numeric text in text box
End If
End With


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Larry Levinson" wrote in
message ...
I have a user form with four textboxes for the user to input

numbers
... How do I tell the macro that it shoud treat the input as a

number
and not as text? this is not about validation. Let's assume,

just for
the sake of arguments that the user is smart enough to put in

numbers
to begin with ...

thanks ...


Larry Levinson
Talking up to the vocal ...
LLevinson*Bloomberg.net
(remove the star etc ....)




Ron de Bruin

UserForms and Variables and Types of data
 
Hi Larry

You must convert the string to a value

MsgBox Val(TextBox1.Value) + Val(TextBox2.Value)
Or
MsgBox CDbl(TextBox1.Value) + CDbl(TextBox2.Value)

If you need some code to validate post back


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Larry Levinson" wrote in message ...
I have a user form with four textboxes for the user to input numbers
... How do I tell the macro that it shoud treat the input as a number
and not as text? this is not about validation. Let's assume, just for
the sake of arguments that the user is smart enough to put in numbers
to begin with ...

thanks ...


Larry Levinson
Talking up to the vocal ...
LLevinson*Bloomberg.net
(remove the star etc ....)




Larry Levinson

UserForms and Variables and Types of data
 
so, assuming the user is putting in a number anyway, it would be


BN = CLng(DataForm.BN.Value)
var textbox ...

right?

"Chip Pearson" wrote:

Larry,

Text boxes always contain text (which may be all numbers), not
actual numeric data. Thus, you need to convert the text to a
number using a function like CInt, CLng, or CDbl. For example,

Dim N As Long
With Me.TextBox1
If IsNumeric(.Text) = True Then
N = CLng(.Text)
Else
' not numeric text in text box
End If
End With


Larry Levinson
Talking up to the vocal ...
LLevinson*Bloomberg.net
(remove the star etc ....)

Chip Pearson

UserForms and Variables and Types of data
 
Yes.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Larry Levinson" wrote in
message ...
so, assuming the user is putting in a number anyway, it would

be


BN = CLng(DataForm.BN.Value)
var textbox ...

right?

"Chip Pearson" wrote:

Larry,

Text boxes always contain text (which may be all numbers), not
actual numeric data. Thus, you need to convert the text to a
number using a function like CInt, CLng, or CDbl. For

example,

Dim N As Long
With Me.TextBox1
If IsNumeric(.Text) = True Then
N = CLng(.Text)
Else
' not numeric text in text box
End If
End With


Larry Levinson
Talking up to the vocal ...
LLevinson*Bloomberg.net
(remove the star etc ....)




Larry Levinson

UserForms and Variables and Types of data
 
grazie .. now, about LONG versus SINGLE data types. one of my
variables gets to be 1,000+ with a decimal. shoud it be single instead
of long?




"Chip Pearson" wrote:

Yes.


Larry Levinson
Talking up to the vocal ...
LLevinson*Bloomberg.net
(remove the star etc ....)

Jake Marx[_3_]

UserForms and Variables and Types of data
 
Hi Larry,

Larry Levinson wrote:
grazie .. now, about LONG versus SINGLE data types. one of my
variables gets to be 1,000+ with a decimal. shoud it be single instead
of long?


Yes. A Long can hold only a whole number, so if you have a decimal part of
the number, you'll need to use Single or Double (depending on what type of
accuracy you want).

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]



All times are GMT +1. The time now is 06:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com