Solved

scanning RTB for matches in VB6

Posted on 2004-04-22
4
315 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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

713 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