Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Word, PowerPoint, Outlook, and Other Office Products > IndexOf for VBA?


Reply
 
Thread Tools Display Modes
  #1  
Old 06-17-2006, 05:03 PM
Sigma Sigma is offline
Centurion
 
Join Date: May 2005
Location: Alberta, Canada
Posts: 110
Default 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
Reply With Quote
  #2  
Old 06-18-2006, 06:53 AM
Timbo's Avatar
Timbo Timbo is offline
Green-Eyed

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Bangkok, Thailand
Posts: 10,261
Default

I'm not a .Net developer so can't be sure what the 'IndexOf' function does. What do you plan to use it to do?
__________________
"He's not the Messiah. He's a very naughty boy!" - Brian's mum

Can't find the answer? >> Try something new!
Become a Professional
Reply With Quote
  #3  
Old 06-18-2006, 08:33 AM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

InStr()
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->