
06-17-2006, 05:03 PM
|
|
Centurion
|
|
Join Date: May 2005
Location: Alberta, Canada
Posts: 110
|
|
IndexOf for VBA?
|
I've been working in vb.net/2005 for a while and am going back to vba for a small project. I am using the following line in vb.net to do some parsing work and was hoping there would be a similar approach available in vba.
Code:
Private Function Parse(ByVal str As String, ByVal start As String, ByVal ending As String, ByVal index As Integer) As String
Dim searcher As Integer
Dim matches As Integer
For searcher = 0 To Len(str)
If Not (searcher + Len(start)) > Len(str) Then
If Not str.IndexOf(start, searcher, Len(start)) = -1 Then
matches = matches + 1
If matches = index Then
Parse = str.Substring(searcher, (str.IndexOf(ending, searcher) + ending.Length) - searcher).Replace( _
start, vbNullString).Replace(ending, vbNullString)
End If
End If
End If
Next
lastGame = True
Parse = vbNullString
End Function
Does something similar to IndexOf exist in vba? I believe I pulled this code off of a posting on this website at somepoint and it works fabulously well. Just really hoping it can be transfered to vba easily. I've changed a few things so far, like str.length to Len(str).....just incase you thought it looks funny  .
Thanks so much!
|
Last edited by Timbo; 06-18-2006 at 06:54 AM.
Reason: Added linebreak to reduce page width
|