Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting whole numbers and decimals from text field

Status
Not open for further replies.

fishtek

Technical User
Aug 21, 2002
56
US
I have a query with a text field similar to the following:

Fail
<24
>24.6
Fail
>100
<45
>100
Fail
77
59.9

I am using the following code to extract numbers from the text but the decimals are removed. Problem is I would like to keep all decimals in the numbers.

Public Function getNum(myField)
Dim s As String, l As Long, x As String
If Len(Trim(Nz(myField, ""))) = 0 Then
getNum = myField
Exit Function
End If
For l = 1 To Len(myField)
x = Mid(myField, l, 1)
If (x >= "0" And x <= "9") Then
s = s & x
End If
Next l
getNum = s
End Function


Can anyone suggest how to alter the code or a better way?


 
Replace this:
If (x >= "0" And x <= "9") Then
with this:
If (x >= "0" And x <= "9") Or x = "." Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top