Advanced Instr


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

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

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center