| | |
How to check data type
![]() |
•
•
Join Date: Jul 2006
Posts: 21
Reputation:
Solved Threads: 1
Guys anyone knows how to check if a value entered in a text box
i.e. text3.text=integer value is integer or long
i found a function that checks wether the text is numeric or not "isNumeric" but i did not find any other function that checks if the value entered is integer?
any help??!!
best regards ,
lover99509
i.e. text3.text=integer value is integer or long
i found a function that checks wether the text is numeric or not "isNumeric" but i did not find any other function that checks if the value entered is integer?
any help??!!
best regards ,
lover99509
Hi
Try With This Code
Try With This Code
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
If Val(Text1.text) > 0 or Text1.text = "0" then Print "Is Integer Else Print "Not Integer" End if
Last edited by Comatose; Aug 7th, 2006 at 11:49 am. Reason: UnNeeded Bold Tags...?
I suggest stopping them from introducing anything other than numbers, right off the bat (in the text1 keypress event):
And then test between the int or long variable types using vartype as so:
Here is a table of such data:
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:
You could also do the same with integer values, as in
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
if vartype(retval) = vbinteger then msgbox "is integer" end if
Here is a table of such data:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
dim TypedData as long TypedData = CLng(Text1.Text)
CInt(text1.text) Last edited by Comatose; Aug 7th, 2006 at 2:43 pm.
I think we're getting away from the original question, which was
Doesn't this mean:
•
•
•
•
Originally Posted by lover99509
Guys anyone knows how to check if a value entered in a text box
i.e. text3.text=integer value is integer or long
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?Or am I interpreting this wrong?
•
•
Join Date: Jul 2006
Posts: 21
Reputation:
Solved Threads: 1
this solution will work
but if i do like this:-
Data accurecy will be lost because if the user entered by mistake 9.8
then when the above instruction is excuted TypedData =10 (!!! rounding)
i have another solution which is using the method inStr which will test if the entered value contains the charecter "."
check if user entered only numeric values and test if it does not contain "."
lover99509
[/LEFT]
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
but if i do like this:-
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
dim TypedData as long TypedData = CLng(Text1.Text)
then when the above instruction is excuted TypedData =10 (!!! rounding)
i have another solution which is using the method inStr which will test if the entered value contains the charecter "."
check if user entered only numeric values and test if it does not contain "."
lover99509
[/LEFT]
Last edited by Comatose; Aug 8th, 2006 at 6:16 am.
•
•
•
•
Originally Posted by WaltP
I think we're getting away from the original question, which was
Doesn't this mean: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?Or am I interpreting this wrong?
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.
Last edited by Comatose; Aug 8th, 2006 at 6:20 am.
•
•
Join Date: Oct 2007
Posts: 2
Reputation:
Solved Threads: 0
Euhm, I have a similair problem.
I wanna make sure a value entered in a console application is not empty, a number, and and intiger. I just started learning VB, so i came up with this noobish code, what can i do better?
I wanna make sure a value entered in a console application is not empty, a number, and and intiger. I just started learning VB, so i came up with this noobish code, what can i do better?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub failsafe(ByVal bericht As String, ByRef cijfer As Integer, ByVal procedure As String) Dim tempVar As String Console.WriteLine(bericht) tempVar = Console.ReadLine 'Check for contents If (tempVar <> "") Then 'Check for numeretical value If IsNumeric(tempVar) Then cijfer = CByte(tempVar) 'Check to see if value is integer If (cijfer >= -2147483648) And (cijfer <= 2147483647) Then 'Procedure that is executed when all creteria are met procedure() Else Main() End If Else Main() End If Else Main() End If End Sub
•
•
Join Date: Nov 2006
Posts: 30
Reputation:
Solved Threads: 4
•
•
•
•
I think we're getting away from the original question, which was
Doesn't this mean: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?Or am I interpreting this wrong?
How about trying the following way???
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim Value As Double Dim IntMaxValue As Integer Dim LongMaxValue As Long IntMaxValue = 32767 LongMaxValue = 2147483647 Value = CDbl(Text1.Text) If Value > LongMaxValue Then MsgBox "Value is double" ElseIf Value > IntMaxValue Then MsgBox "Value is long" Else MsgBox "Value is integer" End If
Last edited by yello; Oct 18th, 2007 at 8:40 pm.
www.easyprograming.com
Make Your Programing Easy
Make Your Programing Easy
![]() |
Similar Threads
- Working with SQL server's Image data type (ASP.NET)
- Check data type input!! (C)
- Help With Data-type Declaration Symbols (Pascal and Delphi)
- Working with SQL's Text data type (ASP.NET)
- Text data type troubles in T-SQL (Database Design)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: running a program on a server
- Next Thread: Sending and Receiving SMS using a GSM modem
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






