Question : Can I write a number extracting algorithm

Hi All!

I would like to be able to extract a product 'base code' from product codes that I am working with in a table.  The problem comes from the fact that product codes may come in any of these forms

1110
'base code only

1110 A
or
1110 A06
'base code and revision number/letter combo

AC 1110
'material prefix before the number

AC 1110 A
or
AC 1110 A06

'both material prefix befor and revision number/letter combo after

What I would want to do is be able to pull 1110 out each time as the 'base number'.  I am TOTALLY not sure this can be done b/c there are so many 'if' cases involved..  But if it CAN be done I would be VERY greatful!  

Thanks so much!

P.S.
(my alternative is to just have a backfilled part number that my user would choose from a different form and then have a blank text box that would prompt the user to manually read that '1110' number from the product number they have and enter it by hand into the blank field.  ...  b/c that's my solution to not being able to write the algorithm myself)

Answer : Can I write a number extracting algorithm

You could use this simple function as shown:

BaseCode = CodeNum(ProductCode)

/gustav
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Function CodeNum(ByVal strCode As String) As Integer
 
  Dim intPos  As Integer
  Dim intNum  As Integer
 
  For intPos = 1 To Len(strCode)
    intNum = Val(Mid(strCode, intPos))
    If intNum = 0 Then
      intPos = intPos + 1
    Else
      Exit For
    End If
  Next
 
  CodeNum = intNum
 
End Function
Random Solutions  
 
programming4us programming4us