timhans
Programmer
- Jun 24, 2009
- 75
Hello,in a earlier thread PHV provided succinct parsing function for a single delimiter of choice but at time's I have need for a multi parsing function. Found the following code which parse's with multiple delimiters, can not get it to work, not sure I am calling it correctly, in query
builder
Parse([Location],) or variations on this, where Location is the sole field in a table, was posted on a Vb website(( Any insight in how to use or retro fit to access is appreciated, thanks
Public Function Parse(ByVal inString, Optional ByVal delimiters)
'Take a string, and return it as a one dimensional array
' of individual values as delimited by any of several
' characters. None of those characters are returned in
' the result. Provide a default list of delimiters, which
' should come from registry. But allow override.
Dim delimitList, oneChar, aWord, codeCount
Dim arrayCodes()
If IsMissing(delimiters) Then
'We should get these from Registry
delimitList = " ,/!| "
'Characters recognized as delimiters
Else
delimitList = delimiters
'user can override if needed
End If
Dim i, j, k
i = Len(inString)
For j = 1 To i
'Read one character at a time
oneChar = VBA.Strings.Mid(inString, j, 1)
k = InStr(delimitList, oneChar)
'Is this one a delimiter?
If k = 0 Then
aWord = aWord & oneChar
'If is isn't, add to the current word
End If
If k <> 0 Or j = i Then
'If it is, or if we're finished
If aWord > "" Then
codeCount = codeCount + 1
ReDim Preserve arrayCodes(codeCount)
arrayCodes(codeCount) = aWord
'Save new word
aWord = ""
End If
End If
Next j
Parse = arrayCodes
'Return the array
End Function
builder
Parse([Location],) or variations on this, where Location is the sole field in a table, was posted on a Vb website(( Any insight in how to use or retro fit to access is appreciated, thanks
Public Function Parse(ByVal inString, Optional ByVal delimiters)
'Take a string, and return it as a one dimensional array
' of individual values as delimited by any of several
' characters. None of those characters are returned in
' the result. Provide a default list of delimiters, which
' should come from registry. But allow override.
Dim delimitList, oneChar, aWord, codeCount
Dim arrayCodes()
If IsMissing(delimiters) Then
'We should get these from Registry
delimitList = " ,/!| "
'Characters recognized as delimiters
Else
delimitList = delimiters
'user can override if needed
End If
Dim i, j, k
i = Len(inString)
For j = 1 To i
'Read one character at a time
oneChar = VBA.Strings.Mid(inString, j, 1)
k = InStr(delimitList, oneChar)
'Is this one a delimiter?
If k = 0 Then
aWord = aWord & oneChar
'If is isn't, add to the current word
End If
If k <> 0 Or j = i Then
'If it is, or if we're finished
If aWord > "" Then
codeCount = codeCount + 1
ReDim Preserve arrayCodes(codeCount)
arrayCodes(codeCount) = aWord
'Save new word
aWord = ""
End If
End If
Next j
Parse = arrayCodes
'Return the array
End Function