DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: Advanced Instr

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Advanced Instr

    [Originally posted by Andrew Murphy]

    I need some sort of replace function that will do the following...

    If I have a string that has the following (I will use VB code for
    simplicity)

    If Label1.Caption = "hi" Then Label1.Caption = "Bye"

    and I want to make it

    If Label12.Caption = "hi" Then Label12.Caption = "Bye"

    then I just do a simple replace. BUT my code which I have.....

    If InStr(1, Form3.Text1.Text, LastName) <> 0 Then ' Check for occurance of
    replaced string
    ÿ ÿ If InStr(1, Form3.Text1.Text, Text1.Text) = 0 Then ' has it already been
    replaced?
    ÿ ÿ ÿ ÿ If MsgBox(&quot;Do you wish all references to change in your text?&quot;,
    vbYesNo) = vbYes Then ' Do they want to replace?
    ÿ ÿ ÿ ÿ ÿ ÿ Form3.Text1.Text = Replace(Form3.Text1.Text, LastName,
    Text1.Text) ' Replace
    ÿ ÿ ÿ ÿ End If
    ÿ ÿ End If
    End If

    Doesn't allowed me to make it go back again, ie replace Label12 with Label1.
    BECAUSE when I do line 2 it is picking up the LABEL1 in label12.ÿ How can I
    make it so that I have an instr couterpart like....

    Public Sub AdvInstr(Start, MainText, StringOne, IsNotPartOf)

    where it checks to see if StringOne is part of string IsNotPartOf when each
    &quot;section&quot; is split up my a vbcrlf a &quot; &quot; (space) or a full stop &quot;.&quot;?

    need futhur explaination?

    Andrew

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Advanced Instr

    [Originally posted by neophile]

    Does this do it for you?...



    Public Function AdvInstr(Start, Text, Find, Optional Ignore, Optional Compare As VbCompareMethod = vbBinaryCompare) As Long
    ÿ Dim lFind As Long
    ÿ Dim lIgnore As Long
    ÿ lFind = InStr(Start, Text, Find, Compare)
    ÿ If Not IsMissing(Ignore) Then
    ÿ ÿ ÿ lIgnore = InStr(lFind, Text, Ignore, Compare)
    ÿ ÿ ÿ While lFind = lIgnore
    ÿ ÿ ÿ ÿ lFind = lFind + 1
    ÿ ÿ ÿ ÿ lFind = InStr(lFind, Text, Find, Compare)
    ÿ ÿ ÿ ÿ If lFind > 0 Then lIgnore = InStr(lFind, Text, Ignore, Compare)
    ÿ ÿ ÿ Wend
    ÿ End If
    ÿ AdvInstr = lFind
    End Function

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links