Solved

scanning RTB for matches in VB6

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
This is about my first experience with programming Arduino.
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…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now