Checking wether a karakter is a number

E

Erwin Bormans

Dear,

I've got a string for example:

"NECO 101880 941 NECO KOZIJNEN"

This string is never the same, but i need the 101880 nr.

Is there a way i can check wether a karakter in that string is a number or
not?

Thanks in advance,
Kind regards,
Erwin
 
B

Bill

You could do something like:

Option Compare Database
Option Explicit
Private Sub TestSub()

Dim strTestString() As String
Dim strMyString As String
Dim I As Integer

strMyString = "NECO 101880 941 NECO KOZIJNEN"
strTestString = Split(strMyString, " ")

For I = 0 To UBound(strTestString)
If IsNumeric(strTestString(I)) Then
MsgBox "Token number " & I & " is numeric."
End If
Next

End Sub
 
D

Douglas J Steele

Unfortunately, you'll get false positives with that approach, since, for
example, IsNumeric("1E2") returns True (Access assumes the E is an exponent,
so that that equals 100)

You may want to use

If Str(Val(strTestString(I))) = strTestString(I) Then
MsgBox "Token number " & I & " is numeric."
End If



"Bill" wrote in message

You could do something like:

Option Compare Database
Option Explicit
Private Sub TestSub()

Dim strTestString() As String
Dim strMyString As String
Dim I As Integer

strMyString = "NECO 101880 941 NECO KOZIJNEN"
strTestString = Split(strMyString, " ")

For I = 0 To UBound(strTestString)
If IsNumeric(strTestString(I)) Then
MsgBox "Token number " & I & " is numeric."
End If
Next

End Sub
 
M

Marshall Barton

Bill said:
Private Sub TestSub()

Dim strTestString() As String
Dim strMyString As String
Dim I As Integer

strMyString = "NECO 101880 941 NECO KOZIJNEN"
strTestString = Split(strMyString, " ")

For I = 0 To UBound(strTestString)
If IsNumeric(strTestString(I)) Then


Rather than IsNumeric, I would test for an all digit token
by using:
If Not strTestString(I) Like "*[!0-9]*" Then
 

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

Top