IsNumeric

R

rml

I'm using the following code:

If Not IsNumeric([POS]) Then
[POS2] = "1000"
Else
[POS2] = [POS]

In POS I have entries that look like this:

2
3
2 (old)
4
Sensor

I would like if any entry had anything numeric in it to not apply the "1000"

Example:
2 would equal 2
3 would equal 3
2 (old) would equal 2 not 1000
Sensor would equal 1000

Basically, If any entry had a single numeric digit "2" or any numeric in it
"2 (old)" to be treated as a numberic.

I hope this makes sense.

Thanks.
 
K

Ken Sheridan

Write a function such as:

Public Function GetNumber(varPos) As String

Dim n As Integer
Dim strChr As String
Dim strNum As String

GetNumber = "1000"

If Not IsNull(varPos) Then
For n = 1 To Len(varPos)
strChr = Mid(varPos, n, 1)
If IsNumeric(strChr) Then
strNum = strNum & strChr
End If
Next n
If Len(strNum) > 0 Then
GetNumber = strNum
End If
End If

End Function

You can then assign a value to Pos2 with a single line:

Pos2= GetNumber(Pos)

I've assumed that if Pos is Null you'd want 1000 returned.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top