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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding first integer

Status
Not open for further replies.

flybravo

Programmer
Jun 30, 2003
35
US
I'm trying to create a script the will take a file name given, find the first instance of any integer.

Ex. I need to be able to take a file name and find the customer ID which is either the first 3 - 5 letters.
AOO1993
BBBA374
 
For i = 1 to Len(FolderName)
If asc(i) <= 48 AND asc(i) >= 57 Then 'its not a number
strCustNum = strCustID & i
Else
exit for 'as soon as it finds a non alpha character is exits
End If
Next
 
Try something like this:
Code:
Function GetCustNum(FileName)
  tmp=FileName
  For i=1 To Len(tmp)-3
    x=Left(tmp,1)
    If x>=&quot;0&quot; Or x<=&quot;9&quot; Then Exit For
    tmp=Mid(tmp,2)
  Next
  GetCustNum=CLng(tmp)
End Function

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top