Find first numeric character

Leo_Polla_Psemata

Registered User.
Local time
Today, 05:27
Joined
Mar 24, 2014
Messages
364
Hi

With this function
Left("NameOfField", InStr(1, "NameOfField"," ",vbTextCompare))

I find the first space in a string and then Left.

What should I type if I wanted to find the position of first number in this string?
 
If you don't know the place of the number,then yours won't work.
You need a function to scan the word, then reveal it:

Usage:
FindFirstNum([field])

Code:
Function FindFirstNum(pvWord)
If not IsNull(pvWord) then 
  For I = 1 to len(pvWord)
     vChr =mid(pvWord,I,1)
     If isNumeric(vChr )           
           FindFirstNum=vChr
           Exit function 
     End if
  Next
End if
 
If you don't know the place of the number,then yours won't work.
You need a function to scan the word, then reveal it:

Usage:
FindFirstNum([field])

Code:
Function FindFirstNum(pvWord)
If not IsNull(pvWord) then 
  For I = 1 to len(pvWord)
     vChr =mid(pvWord,I,1)
     If isNumeric(vChr )           
           FindFirstNum=vChr
           Exit function 
     End if
  Next
End if

And what if I need the position of the first number in the string?
Not to find the first number but the position of the first number.
 
Would that be the "I" in
For I = 1 to len(pvWord)
?
Code:
Function FindFirstNum(pvWord)
If not IsNull(pvWord) then 
  For I = 1 to len(pvWord)
         vChr =mid(pvWord,I,1)
   If isNumeric(vChr )           
      FindFirstNum=[I][B][COLOR=Red]I[/COLOR][/B][/I]
      Exit function 
   End if
  Next
End if
 

Users who are viewing this thread

Back
Top Bottom