Guus2005
AWF VIP
- Local time
- Today, 12:18
- Joined
- Jun 26, 2007
- Messages
- 2,645
This is a faster GetPart function using the Split() command.
Enjoy!
Code:
Public Function GetPart(strString As String, strSep As String, intPart As Integer) As String
'Guus2005 - 2006/2007
'New GetPart function without recursion, returns part "intPart" of "strString" with "strSep" as a separator
'Uses an array and the Split() function.
Dim arr() As String
Dim intHigh As Integer
On Error GoTo Err_GetPart
arr = Split(strString, strSep)
'get number of items in the array
intHigh = UBound(arr) + 1
If intHigh = 0 Then 'No items in array
GetPart = strString
Exit Function
End If
If intPart = 0 Then
GetPart = strString
Exit Function
ElseIf intPart > intHigh Then
intPart = intHigh 'Get the last item
End If
GetPart = Trim(arr(intPart - 1))
Exit_GetPart:
Exit Function
Err_GetPart:
MsgBox Err & " - " & Error$, vbExclamation, "Getpart function"
Resume Exit_GetPart
Resume
End Function