CodeItBetter Programming Another VB Programming Blog

How to find the first number with thousand separator in a string

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'String Manipulation - How to find the first number with thousand separator in a string
'This will return the First number found in the String (includes optional FirstPosition of string)
'This will also find decimal numbers.

Public Function FindFirstNum(ByVal MyString As String, Optional ByVal FirstPos As Integer = 1)
    Dim I As Integer, NumFoundFlag As Boolean, StartPos As Integer
    Dim Char As String
    For I = FirstPos To Len(MyString)
        Char = Mid$(MyString, I, 1)
        If IsNumeric(Char) = True And NumFoundFlag = False Then
            NumFoundFlag = True
            StartPos = I
        ElseIf (IsNumeric(Char) = False And Char <> ",") And NumFoundFlag = True Then
            GoTo ExitHere
        End If
    Next
 
ExitHere:
    FindFirstNum = Mid$(MyString, StartPos, I - StartPos)
End Function
 
'How can I call this function:
'Debug.Print FindFirstNum("Money:34,256 \n\r")
'will display 34,256
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.