Solved

scanning RTB for matches in VB6

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 97
splitOdd10 challenge 5 109
Adoquery sql  left join does not work 25 92
SCRIPT65535: Unexpected call to method or property access video html 5 explorer 3 64
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …

831 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