WorkingVBA
Registered User.
- Local time
- Today, 10:04
- Joined
- Jul 3, 2013
- Messages
- 33
Hi All,
It has been about 4 years since I have done any programming and I am working on a project to parse a long description string, "~" delimeted, in a query. I am making progress and have thusfar been able to capture the substrings using the GetStr() function (all code is below) I am now trying to analyze the strings to determine if the last 5 characters are part of a zipcode. The problem is that for some reason my counter (j) in the getAddress() function is reset to 0 after I call the GetStr() function. I have no idea why this is happening though I have a feeling my long absence from the dev world is probably part of the problem. I know the code below is a bit crude, but I am looking for functional - this is a one time data conversion project.
Thanks I super appreciate any help
It has been about 4 years since I have done any programming and I am working on a project to parse a long description string, "~" delimeted, in a query. I am making progress and have thusfar been able to capture the substrings using the GetStr() function (all code is below) I am now trying to analyze the strings to determine if the last 5 characters are part of a zipcode. The problem is that for some reason my counter (j) in the getAddress() function is reset to 0 after I call the GetStr() function. I have no idea why this is happening though I have a feeling my long absence from the dev world is probably part of the problem. I know the code below is a bit crude, but I am looking for functional - this is a one time data conversion project.
Thanks I super appreciate any help
Code:
Sub Test()
Dim vTestString As String
vTestString = "Blablablabla~600 Blablabla Ave,~City STC 29954~~Area takeoff for Blablabla; Blablabla; and 2nd Blablabla~Save original Blablabla, add in new Blablabla to Blablabla and Blablabla for Blablabla.~~PATH: M:\Blablabla\Blablabla"
' Call function GetAddress with test String
GetAddress (vTestString)
End Sub
'========================================
Function GetAddress(vStr As String) As String
Dim j As Integer
Dim vEnd As Integer
Dim vTestStr As String
Dim vTestVal As Double
Dim vReturnStr As String
j = 1
vEnd = 3 'CntChar(vString, "~")
vTestStr = ""
vTestVal = 0
vReturnStr = ""
Do While j <= vEnd
vTestStr = Trim(GetStr(j, vStr))
vTestVal = Val(vTestStr)
If vTestVal >= 10000 And vTestVal <= 99999 Then
vReturnStr = vTestStr
End If
j = j + 1
Loop
GetAddress = vReturnStr
End Function
'========================================
Function GetStr(vLoc As Integer, vString As String) As String
Dim i As Integer
Dim vCurLoc As Integer
Dim vStrLen As Integer
Dim vChar As String
Dim vLastChar As String
Dim vSrchStr As String
Dim vReturnStr As String
i = 1
vCurLoc = 0
vStrLen = Len(vString)
vChar = ""
vLastChar = ""
vReturnStr = ""
vSrchStr = "~"
vLoc = vLoc - 1
Do While i <= vStrLen
vChar = Mid(vString, i, 1)
If vCurLoc = vLoc And vChar <> vSrchStr Then
vReturnStr = vReturnStr & vChar
End If
If vChar = vSrchStr And vLastChar <> vSrchStr Then
vCurLoc = vCurLoc + 1
End If
vLastChar = vChar
i = i + 1
Loop
GetStr = vReturnStr
End Function
'========================================