Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default 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 ....)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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 ....)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default 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 ....)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default 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 ....)
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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 ....)





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default 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 ....)
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default 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]

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I hide unused file types from file types list in save dial Estra Q Excel Discussion (Misc queries) 1 December 17th 09 12:36 PM
Excel 2007 error "some chart types cannot be combined with other chart types. Select a different chart types" roadsidetree Charts and Charting in Excel 15 June 2nd 09 10:53 AM
Using SUMPRODUCT, 3 variables, 2 types of data in 1 column Dana M Excel Worksheet Functions 3 February 7th 09 01:31 PM
Data types when importing Excel data to SQLServer [email protected] Excel Discussion (Misc queries) 1 September 27th 06 12:48 PM
Public Variables with UserForms Mark Worthington Excel Programming 3 February 26th 04 12:26 AM


All times are GMT +1. The time now is 02:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"