Results 1 to 9 of 9

Thread: Find & Replace text ??

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Skudeneshavn, Norway
    Posts
    38
    Hi

    Find & Replace text in a textbox.

    Has any of you done this. I tried "InStr" but I don't know
    how it works.

    Hope you can help

    Chris
    Christian Davidsen

    If you go to sleep with an itchy
    ass, you wake up with smelly fingers.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    dim x as string
    x = text1.text
    x = replace(x,"whatword","replacement")
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Look up msdn.microsoft.com for information on instr. Look here: Microsoft Visual Studio Documentation-->VB Documentation-->Reference-->Language Reference-->Functions-->I-->Instr

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715

    <!>

    HeSaidJoe, I didn't see your post.

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    No problem
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Skudeneshavn, Norway
    Posts
    38

    :-)

    Thanks for the replies

    Best Regards,

    Chris Davidsen
    Christian Davidsen

    If you go to sleep with an itchy
    ass, you wake up with smelly fingers.

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Skudeneshavn, Norway
    Posts
    38

    hmmmm

    This code does not compute
    VB reject's the word "replace" in the code

    dim x as string
    x = text1.text
    x = replace(x,"whatword","replacement")

    Is there something wrong with this code?

    Chris

    Christian Davidsen

    If you go to sleep with an itchy
    ass, you wake up with smelly fingers.

  8. #8
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Shoot..you must not have VB6
    Tested this but if you hav VB5 or 4 it won't work for you
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    
       Dim x As String
    x = "Help me with whatword in this sentence"
    x = Replace(x, "whatword", "My new Word")
    
    MsgBox x
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  9. #9
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'this works in VB5 for search and replace
    
    Option Explicit
    Option Compare Text
    
    
    '[begin of code]
    'Author: John Percival
    'Origin: http://www.vb-world.net/tips/tip110.html
    'Purpose: A Find-and-Replace function for VB5 users
    'Version: VB5+
    
    'function to do the work
    
    Public Function replaceall(searchstring As String, _
    findstring As String, replacestring As String) As String
    
    Dim curpos As Long
    
    curpos = 1
    
    Do
    
    curpos = InStr(curpos, searchstring, findstring)
    searchstring = Left$(searchstring, curpos - 1) & _
    replacestring & Right$(searchstring, Len(searchstring) _
    - curpos - Len(findstring) + 1)
    
    Loop Until InStr(searchstring, findstring) = 0
    
    replaceall = searchstring
    
    End Function
    
    'call to get the work done
    'x = string to be searched
    'y = what to search for
    'z = what to replace it with
    
    Private Sub Command1_Click()
    
    Dim x As String, y As String, z As String
    
    x = "What in the world are we Searching for here, anyway?"
    y = "Searching for"
    z = "Replacement Value"
    Call replaceall(x, y, z)
    MsgBox x
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width