Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 ....) |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 ....) |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 ....) |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 ....) |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 ....) |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 ....) |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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] |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How can I hide unused file types from file types list in save dial | Excel Discussion (Misc queries) | |||
Excel 2007 error "some chart types cannot be combined with other chart types. Select a different chart types" | Charts and Charting in Excel | |||
Using SUMPRODUCT, 3 variables, 2 types of data in 1 column | Excel Worksheet Functions | |||
Data types when importing Excel data to SQLServer | Excel Discussion (Misc queries) | |||
Public Variables with UserForms | Excel Programming |