Re: Searching a file
From: Rick Rothstein (rickNOSPAMnews_at_NOSPAMcomcast.net)
Date: 05/14/04
- Next message: Jim Deutch: "Re: bound vs unbound"
- Previous message: Jim Deutch: "Re: Picturebox reference problem"
- In reply to: Sivaprasad: "Re: Searching a file"
- Next in thread: Sivaprasad: "Re: Searching a file"
- Reply: Sivaprasad: "Re: Searching a file"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 14 May 2004 12:06:17 -0400
A one Meg file is nothing to the routine I posted (I've used it up to 10
Megs and not really seen a problem). If you knew all the delimiters for
words in the text the doctors are producing, that would be great (I'm
assuming the "ph" you mentioned could come at the end of a sentence,
next to a parenthesis, in quotes, etc.) because a "filter" for them
could be devised... but you would have to know them all.
Another alternative, although it requires distributing another control
with your project, is to use the Microsoft Rich Textbox Control (it's in
the list of Controls you get by clicking Project/Components on VB's
menubar). It has a Find method that is similar to InStr, except that one
of its arguments allows you to filter on "whole words". Also, it
highlights the text as it finds it so you can replace it quite easily
using the SelText property. AND, it has a LoadFile method (or,
alternately, a FileName property) which loads large files (much larger
than we are talking about) lightning quick as well as a SaveFile method
to put the text back on the hard drive. Here is a small, demo piece of
code that will replace all instances of the word "ph" (whether upper or
lower case) with the word "Pharmaceutical list" (it assumes you have
already loaded the RichTextBox with the text from the file).
Private Sub Command1_Click()
Dim Position As Long
Dim Abbreviation As String
Abbreviation = "ph"
With RichTextBox1
Position = .Find(Abbreviation, , , rtfWholeWord)
Do While Position > -1
.SelText = "Pharmaceutical list"
Position = .Find(Abbreviation, Position + _
Len(Abbreviation), , rtfWholeWord)
Loop
End With
End Sub
Of course, you would have to devise the storage mechanism to equate your
abbreviations with their full-out text equivalents and create a
surrounding loop to feed each possible abbreviation into the variable
named Abbreviation, but that is relatively easy to do.
Rick - MVP
"Sivaprasad" <sshankaran@hotmail.com> wrote in message
news:udHpjZcOEHA.268@TK2MSFTNGP11.phx.gbl...
> Sorry for not being clear about it.
>
> Basicaly i am working on clinical software.
> The doctors will have shorthands for their diagnosis or procedures
they do.
> They don't want to type in the whole text every time.
>
> So i am providing them a way to enter the shorthand text and I will
replace
> the whole text with the actual text.
> The data is in the table. I can decide how i want the data.
>
> Yah as you said if i give a unique symbol to all the shorthand text
then i
> can search. But is that a best way to do that.
> In some cases the file goes up to more than a meg.
>
> Thanks rick, thanks for your response.
> Siva
>
>
> "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
> news:ORWGy2bOEHA.3124@TK2MSFTNGP12.phx.gbl...
> > I made the assumption originally that we were talking about a text
file;
> > but based on your answer, I'm not so sure. I was expecting you to
tell
> > me your file was "so many" Megs large, not the number of pages. Can
you
> > clarify what you meant when you said "I have a large data to be
> > searched"? Where is this data housed at. If, as J French guessed, we
are
> > talking about the equivalent of 21 pages of text in a text file,
then
> > yes, read it all in one fell swoop.
> >
> > Dim FileNum As Integer
> > Dim TotalFile As String
> > FileNum = FreeFile
> > ' Reads the entire file into memory all at once
> > Open "c:\SomeDirectory\TextFile.txt" For Binary As #FileNum
> > TotalFile = Space(LOF(FileNum))
> > Get #FileNum, , TotalFile
> > Close #FileNum
> >
> > After executing the above code, the variable named TotalFile will
> > contain the entire contents of the file that was Open'ed (here, in
my
> > example, I called it "c:\SomeDirectory\TextFile.txt"). Now,
depending on
> > what you want to do, you should be able to parse it using standard
> > String functions.
> >
> > Rick - MVP
> >
> >
> > "Sivaprasad" <sshankaran@hotmail.com> wrote in message
> > news:eOcQecQOEHA.3044@TK2MSFTNGP10.phx.gbl...
> > > It is about 21 pages.
> > > So i thought, if i put this in an xml file and loading it with an
XML
> > > Document object will consume time. Wouldn't it be slow?
> > >
> > >
> > > "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message
> > > news:eYhUXMQOEHA.2524@TK2MSFTNGP11.phx.gbl...
> > > > > I have a large data to be searched.
> > > >
> > > > How large is "large"?
> > > >
> > > > Rick - MVP
> > > >
> > > >
> > > >
> > > > > I am wondering which will be the best way to search.
> > > > > The purpose is actually like a shorthand.
> > > > > When the user enter a word in a text box, I want to pull the
> > > > corresponding
> > > > > text for that word.
> > > > > So should i put the whole thing in an XML file and search it
or
> > should
> > > > i use
> > > > > an .ini file, and search the ini file, or is there any other
way
> > > > > I can achieve the result faster.
> > > > > I am using VB to code this.
> > > > >
> > > > > Please let me know
> > > > > Thanks in advance
> > > > > Siva
> > > > >
> > > > >
> > > > >
> > > >
> > >
> > >
> >
>
>
- Next message: Jim Deutch: "Re: bound vs unbound"
- Previous message: Jim Deutch: "Re: Picturebox reference problem"
- In reply to: Sivaprasad: "Re: Searching a file"
- Next in thread: Sivaprasad: "Re: Searching a file"
- Reply: Sivaprasad: "Re: Searching a file"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|