DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Find and highlight text

  1. #1
    Join Date
    Nov 2005
    Location
    Edmonton, Alberta, Canada
    Posts
    30

    Find and highlight text

    Hi,
    I'm a beginner at VB6.
    I have a block of text that I want to find a certain word in and then highlight the word. I can get the text to be found by using an inputbox; user would type in the text to be found. I think the following code would then be used to highlight the found text:
    text1.selStart=0
    text1.selLength=len(text1.text)

    I'm not quite sure how to use the instr() function. I know it is probably the function to use to find certain text within a block of text, but everytime I try to use the instr() function I get an error message. Can someone show me where I could find the code to: FIND TEXT WITHIN A BLOCK OF TEXT AND THEN HIGHLIGHT THE FOUND TEXT. If I could see the code I would begin to understand how to use the instr() function.

    I'd be very apprciative if someone could help!
    Thanks in advance to whomever may offer some advice.
    urbaud

  2. #2
    Join Date
    Mar 2006
    Posts
    4
    herz the instr() function with a description of wat value it returns

    Syntax: Instr([startingPosition,]String expression,substring]
    returns: A numeric value that is the position within the string where the substring begins; returns 0 if the substring is not found

    eg: if u want to check the presence of an alphabet "a" in string "aries"
    u would specify the condition as :
    if instr(0,"aries","a")
    in case of repetition of an alphabet...the compiler return the value of the first occurence of the substring..

    hope this works out for u..

  3. #3
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    Code:
     
       Dim k As Long
        Dim search As String
        
        search = "foo"
        k = InStr(1, Text1.Text, search)
        If k > 0 Then
            Text1.SelStart = k - 1
            Text1.SelLength = Len(search)
        End If
    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

Similar Threads

  1. Datagrid - Highlight selected row
    By Dan Thibodeaux in forum .NET
    Replies: 1
    Last Post: 04-23-2002, 11:23 AM
  2. Find Method with Multiple Criteria
    By Karl Robinson in forum VB Classic
    Replies: 3
    Last Post: 07-24-2001, 03:15 AM
  3. Find Method with Multiple Criteria
    By Karl Robinson in forum VB Classic
    Replies: 7
    Last Post: 07-23-2001, 10:58 AM
  4. SEEK vs FIND vs FILTER
    By Dante in forum VB Classic
    Replies: 1
    Last Post: 06-30-2000, 12:47 PM

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