There is no function to do what you want. All you have is a string of characters. When you convert into a number, you'll know. Short of counting the characters and analyzing whether the characters are greater than "32767" or "65535", just convert into a long and don't worry about it.
WaltP
Posting Sage w/ dash of thyme
10,507 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
I suggest stopping them from introducing anything other than numbers, right off the bat (in the text1 keypress event):
Private Sub Text1_KeyPress(KeyAscii As Integer)
'
' Invalidate keystroke if not a digit, decimal point or backspace.
'
If (Not IsNumeric(Chr$(KeyAscii)) And (Chr$(KeyAscii) <> "." And Chr$(KeyAscii) <> vbBack)) Then KeyAscii = 0
End Sub
And then test between the int or long variable types using vartype as so:
if vartype(retval) = vbinteger then
msgbox "is integer"
end if
Here is a table of such data:
0 vbEmpty Empty and not initialized argument
1 vbNull Invalid data or a null string argument
2 vbInteger Integer argument
3 vbLong Long argument
4 vbSingle Single argument
5 vbDouble Double argument
6 vbCurrency Currency argument
7 vbDate Date argument
8 vbString String argument
9 vbObject Object argument
10 vbError Error argument
11 vbBoolean Boolean argument
12 vbVariant Variant argument
13 vbDataObject Data Access Object (DAO) argument; an advanced database value such as a field or record
14 vbDecimal Decimal argument
17 vbByte Byte argument
8192+int vbArray Array argument of the type specified by the int addition to 81920 vbEmpty Empty and not initialized
Now, as was stated above, a textbox will only return a string. There is no other means by which a textbox will contain data. A number, too, can be a string, "1" is a string, but it's a character that represents a digit. If you need a number in a specific variable type, though, you can "cast" it to the desired type. So, if you need the information in the textbox to be a long, you can simply assign a variable to it's cast type:
dim TypedData as long
TypedData = CLng(Text1.Text)
You could also do the same with integer values, as in CInt(text1.text)
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
I think we're getting away from the original question, which was
Guys anyone knows how to check if a value entered in a text box
i.e. text3.text=integer value is integer or long Doesn't this mean:[INDENT]I have a number in a text box. How can I tell if I need anInteger or a Long when it's converted from ASCII to binary?
[/INDENT]Or am I interpreting this wrong?
WaltP
Posting Sage w/ dash of thyme
10,507 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
I think we're getting away from the original question, which was
Doesn't this mean:[INDENT]I have a number in a text box. How can I tell if I need an Integer or a Long when it's converted from ASCII to binary?
[/INDENT]Or am I interpreting this wrong?
I would guess that he wants to ensure that numbers are all that is in the textbox, especially if he wants to see if the data entered is a long or integer.... so It looks to me as though the information is entirely relevant.
Lover99509: Right, because long is a integer type. You could cast it to a single, instead of clng, you could use csng, or cdbl. Which would cast it to a single or a double, which are both floating points. That would maintain your decimal point, and solve you from having to do string parsing.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215