Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

scanning RTB for matches in VB6

Posted on 2004-04-22
4
Medium Priority
?
322 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 2000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

In this post we will learn different types of Android Layout and some basics of an Android App.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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…
Starting up a Project

618 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