By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,335 Members | 2,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,335 IT Pros & Developers. It's quick & easy.

Help on String and Integer

werks
100+
P: 220
Hi there programmers.

How can you tell if the input value in a textbox is an Integer or String is there any code to know this?
Jan 31 '08 #1
Share this Question
Share on Google+
7 Replies


daniel aristidou
100+
P: 491
Hi there programmers.

How can you tell if the input value in a textbox is an Integer or String is there any code to know this?
Expand|Select|Wrap|Line Numbers
  1.  If isnumeric(textbox.text) = True then
  2. Msgbox("I am a number")
  3. Else
  4. msgbox("I'M not anumber ,im mostlikely a string")
  5. End if
  6.  
This help?
Jan 31 '08 #2

werks
100+
P: 220
Expand|Select|Wrap|Line Numbers
  1.  If isnumeric(textbox.text) = True then
  2. Msgbox("I am a number")
  3. Else
  4. msgbox("I'M not anumber ,im mostlikely a string")
  5. End if
  6.  
This help?
Thank you! Thank you! Thank You! very much. You saved my day.


Better Than Yesterday ^^
Jan 31 '08 #3

Expert 5K+
P: 8,434
I'd just like to point out that by definition, the value in a textbox is always a string. What you're testing is whether it's possible for VB to convert that string to a number. (Note, IsNumeric() function won't care whether it's an integer - it could be too large for instance).

Oh, and a quick tip, daniel. If you're testing a logical value, there's no point in comparing it to True. It already is True or False. So in this example, the code
If IsNumeric(textbox.Text) = True Then
works exactly the same as
If IsNumeric(textbox.Text) Then.
Except that depending on how smart the compiler is, the shorter version might execute ever so slightyl faster.
Feb 1 '08 #4

P: 68
Hi there programmers.

How can you tell if the input value in a textbox is an Integer or String is there any code to know this?

TextBox's Text Property must be String, if u want to check Integer, there is no fucntion for that for ur need u must take some other way.
Feb 1 '08 #5

Expert 5K+
P: 8,434
TextBox's Text Property must be String, if u want to check Integer, there is no fucntion for that for ur need u must take some other way.
daniel aristidou already provided a solution which "werks" :) though it may have problems with large numbers or decimals.
Feb 1 '08 #6

lotus18
100+
P: 866
Oh, and a quick tip, daniel. If you're testing a logical value, there's no point in comparing it to True. It already is True or False. So in this example, the code
If IsNumeric(textbox.Text) = True Then
works exactly the same as
If IsNumeric(textbox.Text) Then.
Except that depending on how smart the compiler is, the shorter version might execute ever so slightyl faster.
I didn't know this huh? I learned something new for this day. haha : )

Rey Sean
Feb 1 '08 #7

daniel aristidou
100+
P: 491
Hey...killer..you have a valid point... i already knew that...i just always put = True in when trying to explain or if there is more than one statement...so as not to get confused.....
Good point though....
Feb 1 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.