Solved

scanning RTB for matches in VB6

Posted on 2004-04-22
4
317 Views
Last Modified: 2010-04-17
I am trying to build an application that will read text from a .txt file, and scan for the text in a richtextbox, When a word from my .txt  file is found it will then change its color to red in the RTB
I am able to search for one word at a time from a text box that i added to the form and it will color the text red also.
i added another command button for the option of searching from my textfile
I dont seem to be able to get the strings into an array correctly or something mabey one of you will know what i need to do
my text file i am reading from is named basewords
and i filled iit with the words like this
word|word|word|word|word|


Below is what i have so far

Dim fs, f
    Dim sFileContents As String
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.OpenTextFile(app.path + \basewords, ForReading, 0)
    sFileContents = f.ReadLine
    f.Close
    Set f = Nothing
    Set fs = Nothing
0
Comment
Question by:BI5HOP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Expert Comment

by:rajaloysious
ID: 10896431
First thing
 Set f = fs.OpenTextFile(app.path + \basewords, ForReading, 0)
should be
 Set f = fs.OpenTextFile(app.path +" \basewords", ForReading, 0)
Let me know if this doesnt work still - i ll have a look.

Good luck
0
 
LVL 8

Accepted Solution

by:
harris_c earned 500 total points
ID: 10896782
Private Sub Command1_Click()
    Dim arrBaseWords() As String
    Dim bufFile As String
    Dim fHandle As Integer
   
    fHandle = FreeFile
   
    Open "c:\temp\basewords.txt" For Binary As fHandle
        bufFile = Space$(LOF(fHandle))
        Get #fHandle, 1, bufFile
    Close fHandle
   
    arrBaseWords() = Split(bufFile, "|")
   
   
    '
    Dim txtRtf As String
    txtRtf = UCase$(RichTextBox1.Text)
    Dim current As Integer
    Dim previous As Integer
    Dim x As Integer
   
    For x = 0 To UBound(arrBaseWords)
        previous = 0
        If arrBaseWords(x) <> "" Then
            current = InStr(previous + 1, txtRtf, UCase$(arrBaseWords(x)))
            If current > 0 Then
                RichTextBox1.SelStart = current - 1
                RichTextBox1.SelLength = Len(arrBaseWords(x))
                RichTextBox1.SelColor = vbRed
                previous = current
            End If
        End If
    Next x
       
End Sub





hec",)
0
 

Author Comment

by:BI5HOP
ID: 10901492
Outstanding harris_c
i had a guy helping me last night and we got it but it had faults like when we added to the basefile it wold always find the text and it wouldnt run smooth through the scan it went back and forth your code is awesome thank you :)
it scans smooth through huge files also :)
great job
0
 

Author Comment

by:BI5HOP
ID: 10903285
one lst thin i guess i forgot to say i have two check boxes in the application
they are
check1(0) this one is for exact text but not case
check1(1)  this one is for exact case and text
obviously  they dont work on this last button where does the code go in the above click event ?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question