|
-
Jan 20th, 2007, 09:47 AM
#1
Thread Starter
Junior Member
check floating point
I want to make an error checking to check whether the value in the textbox is a floating point or not. Please help me...........
-
Jan 20th, 2007, 10:15 AM
#2
Re: check floating point
Hi bfughinelaihl ! Welcome to VBForums. 
Try the following code. I've assumed if a user entered 1., it will be NON-floating point. But if s/he enters 1.0, it will be floating point.
If you don't want this check, omit the code in bold font.
VB Code:
Option Explicit
Private Sub Command1_Click()
MsgBox IsFloatingPoint(Text1.Text)
End Sub
Private Function IsFloatingPoint(strText As String) As Boolean
Dim pos As Long
If IsNumeric(strText) Then
pos = InStr(1, strText, ".")
IsFloatingPoint = (pos > 0) [b]And (pos < Len(strText))[/b]
End If
End Function
Last edited by iPrank; Jan 20th, 2007 at 10:19 AM.
-
Jan 20th, 2007, 07:29 PM
#3
Thread Starter
Junior Member
Re: check floating point
Thanks a lot.... But what is <pos = InStr(1, strText, ".")> mean ? I cannot find it in books.
-
Jan 20th, 2007, 08:38 PM
#4
Frenzied Member
Re: check floating point
InStr tests wether one string is present in another string.
In this case it looks for the decimal separator.
Note that this will think that "a.b" is a float as well.
You could add an IsNumeric test for more robustness.
Another way would be IsFloat = (number <> Fix(number))
-
Jan 20th, 2007, 08:55 PM
#5
Thread Starter
Junior Member
Re: check floating point
How to apply <IsFloat = (number <> Fix(number))> ?
And how to get the value after the decimal point ?
Last edited by bfughinelaihl; Jan 20th, 2007 at 09:17 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|