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

stripping a field...

Status
Not open for further replies.

soda

Technical User
May 30, 2001
3
US
i am looking to have a field read another one that contains both alpha & numeric values yet only pick up the numeric value... Any ideas?
 
Probably not what you're looking for. Even if it is, it is not really "complete", as I did not even attempt to deal with scientific notation or exponentials, not to mention Logs .... the list is simply to long for me to maintain an interest.

Code:
Public Function basOnlyNum(strIn As String) As String

    'to return only the Numeric Part (Characters) from the input

    'Example Usage:
    '? basOnlyNum("1lkj34l;kj2435")
    '1342435

    'Print basOnlyNum("1lkj34l.kj2435")
    '1342435

    'Print basOnlyNum("1lkj34l.kj2.435")
    '1342.435


    Dim Idx As Integer
    Dim strChr As String * 1
    Dim strPrevChr As String * 1
    Dim strTemp As String

    For Idx = 1 To Len(strIn)

        strChr = Mid(strIn, Idx, 1)     'Just to Get a chr

        If (IsNumeric(strChr)) Then     'If it is a NUMBER, add to the output
            strTemp = strTemp & strChr
        End If

        'Here for what ever other "Stuff" might be in a number,

        'LIKE a decimal point?
        'If it is the FIRST Chr AND the NEXT Chr is Numer
        If ((strChr = ".") And _
            (Idx = 1) And _
             IsNumeric((Mid(strIn, Idx + 1, 1)))) Then
            strTemp = strTemp & strChr
        End If

        'LIKE a decimal point?
        'If it is preceeded by a NUM
        If (strChr = "." And IsNumeric(strPrevChr)) Then
            strTemp = strTemp & strChr
        End If

        strPrevChr = strChr

    Next Idx

    basOnlyNum = strTemp

End Function


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top