[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Best way to replace text in a rich textbox

Saucer Man

5/26/2012 8:17:00 PM

I have a rich textbox loaded with a 90mb file. I am trying to replace
vbCrLf and vbTab. I am doing...

tbox.txt = Replace(tbox.txt, vbCrLf, vbNull)
tbox.txt = Replace(tbox.txt, vbTab, vbNull)

Each line takes an extremely long time. Is there a better way of doing
this?

--
Thanks.


42 Answers

GS

5/26/2012 8:26:00 PM

0

After serious thinking Saucer Man wrote :
> I have a rich textbox loaded with a 90mb file. I am trying to replace vbCrLf
> and vbTab. I am doing...
>
> tbox.txt = Replace(tbox.txt, vbCrLf, vbNull)
> tbox.txt = Replace(tbox.txt, vbTab, vbNull)
>
> Each line takes an extremely long time. Is there a better way of doing this?

Can you do this *before* dumping the file into the RT? (Assumes you
won't need the vbCrLf/vbTab characters, *and* that the text file is
read into a string data type that can be processed in memory)

--
Garry

Free usenet access at http://www.eternal-sep...
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Saucer Man

5/26/2012 8:44:00 PM

0

Well, the file already exists as a text file. How can I do it as I add the
file to the rich text box?

--
Thanks.
"GS" <gs@somewhere.net> wrote in message news:jpre9a$2a7$1@dont-email.me...
> After serious thinking Saucer Man wrote :
>> I have a rich textbox loaded with a 90mb file. I am trying to replace
>> vbCrLf and vbTab. I am doing...
>>
>> tbox.txt = Replace(tbox.txt, vbCrLf, vbNull)
>> tbox.txt = Replace(tbox.txt, vbTab, vbNull)
>>
>> Each line takes an extremely long time. Is there a better way of doing
>> this?
>
> Can you do this *before* dumping the file into the RT? (Assumes you won't
> need the vbCrLf/vbTab characters, *and* that the text file is read into a
> string data type that can be processed in memory)
>
> --
> Garry
>
> Free usenet access at http://www.eternal-sep...
> ClassicVB Users Regroup!
> comp.lang.basic.visual.misc
> microsoft.public.vb.general.discussion
>
>


GS

5/26/2012 9:34:00 PM

0

After serious thinking Saucer Man wrote :
> Well, the file already exists as a text file. How can I do it as I add the
> file to the rich text box?

How are you adding the file now? Surely you aren't reading in one line
at a time, right!

If you need the lines then put the file contents into an array via
Split() and specify vbCrLf as the delimiter. You can replace any vbTab
characters *before* putting the contents into the array. When done,
assign the array to RT.Text.

--
Garry

Free usenet access at http://www.eternal-sep...
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Mayayana

5/26/2012 9:52:00 PM

0

We had a long discussion about this some years ago.
RTB methods are fairly slow. Replace is surpridingly
slow. But an RTB can load data into it's window very
quickly. Try this sample test:

http://www.jsware.net/jsware/test/r...

As far as I know, the method of pointing an integer array
at the string and tokenizing it is the fastest method. Though
of course it would be faster not to let the file get to 90 MB. :)

--
--
"Saucer Man" <saucerman@nospam.net> wrote in message
news:jprdn9$3oe$1@news.mixmin.net...
|I have a rich textbox loaded with a 90mb file. I am trying to replace
| vbCrLf and vbTab. I am doing...
|
| tbox.txt = Replace(tbox.txt, vbCrLf, vbNull)
| tbox.txt = Replace(tbox.txt, vbTab, vbNull)
|
| Each line takes an extremely long time. Is there a better way of doing
| this?
|
| --
| Thanks.
|
|


GS

5/26/2012 11:39:00 PM

0

Mayayana used his keyboard to write :
> We had a long discussion about this some years ago.
> RTB methods are fairly slow. Replace is surpridingly
> slow. But an RTB can load data into it's window very
> quickly. Try this sample test:
>
> http://www.jsware.net/jsware/test/r...
>
> As far as I know, the method of pointing an integer array
> at the string and tokenizing it is the fastest method. Though
> of course it would be faster not to let the file get to 90 MB. :)
>
> --
> --
> "Saucer Man" <saucerman@nospam.net> wrote in message
> news:jprdn9$3oe$1@news.mixmin.net...
> |I have a rich textbox loaded with a 90mb file. I am trying to replace
> | vbCrLf and vbTab. I am doing...
> |
> | tbox.txt = Replace(tbox.txt, vbCrLf, vbNull)
> | tbox.txt = Replace(tbox.txt, vbTab, vbNull)
> |
> | Each line takes an extremely long time. Is there a better way of doing
> | this?
> |
> | --
> | Thanks.
> |
> |

I recall reading that discussion and so is what I was eluding to. I
couldn't find it, though, but now that you posted this I'll stop
looking for it.<g>

--
Garry

Free usenet access at http://www.eternal-sep...
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


GS

5/26/2012 11:43:00 PM

0

on 5/26/2012, Mayayana supposed :
> We had a long discussion about this some years ago.
> RTB methods are fairly slow. Replace is surpridingly
> slow. But an RTB can load data into it's window very
> quickly. Try this sample test:
>
> http://www.jsware.net/jsware/test/r...
>
> As far as I know, the method of pointing an integer array
> at the string and tokenizing it is the fastest method. Though
> of course it would be faster not to let the file get to 90 MB. :)
>
> --
> --
> "Saucer Man" <saucerman@nospam.net> wrote in message
> news:jprdn9$3oe$1@news.mixmin.net...
> |I have a rich textbox loaded with a 90mb file. I am trying to replace
> | vbCrLf and vbTab. I am doing...
> |
> | tbox.txt = Replace(tbox.txt, vbCrLf, vbNull)
> | tbox.txt = Replace(tbox.txt, vbTab, vbNull)
> |
> | Each line takes an extremely long time. Is there a better way of doing
> | this?
> |
> | --
> | Thanks.
> |
> |

I was thinking the 90mb file's content could be done in blocks,
perhaps?

--
Garry

Free usenet access at http://www.eternal-sep...
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Mayayana

5/27/2012 1:01:00 AM

0

| I recall reading that discussion and so is what I was eluding to. I
| couldn't find it, though, but now that you posted this I'll stop
| looking for it.<g>
|

I'd be surprised if you did find it. It was a very long
time ago, and Google's not what it used to be. I think
it might have been 5 years or so. (? I hesitate to guess.
I seem to have reached an age some time ago where
everything notable that I remember happened 20 years
ago. :)

Credit where credit is due: Most of the ideas and
methods that came out of that discussion were thanks
to Mike Williams.


Jim Mack

5/27/2012 1:19:00 AM

0

> I have a rich textbox loaded with a 90mb file. I am trying to replace
> vbCrLf and vbTab. I am doing...
>
> tbox.txt = Replace(tbox.txt, vbCrLf, vbNull)
> tbox.txt = Replace(tbox.txt, vbTab, vbNull)
>
> Each line takes an extremely long time. Is there a better way of doing
> this?

Are you sure vbNull is what you want here? I would guess not.

--
Jim


Jimekus

5/27/2012 1:37:00 AM

0



Saucer Man wrote:
> I have a rich textbox loaded with a 90mb file. I am trying to replace
> vbCrLf and vbTab. I am doing...
>
> tbox.txt = Replace(tbox.txt, vbCrLf, vbNull)
> tbox.txt = Replace(tbox.txt, vbTab, vbNull)
>
> Each line takes an extremely long time. Is there a better way of doing
> this?
>
> --
> Thanks.

My cut routine is very fast. Not tried on 90Mb files but on smaller
files always works well. Replace "vbNullstring" with a replace text
and maybe modify ".Find" position. Your slowness comes from converting
the richtext to a string each time.

'\\ cut all
StartPos = .DocText.SelStart
CutWhat = .DocText.SelText
LRWhat = Len(CutWhat)
c = StartPos
.DocText.Visible = False

While c >= Zero

.DocText.SelStart = c
.DocText.SelLength = LRWhat
.DocText.SelText = vbNullString

c = .DocText.Find(CutWhat, c + One, ,
rtfNoHighlight)
Wend
.DocText.SelStart = StartPos
.DocText.Visible = True

Mayayana

5/27/2012 2:10:00 AM

0


| My cut routine is very fast.

I think that if you test that against working on the
text string directly, you'll find that the RTB methods
are the slowest. The Replace function is notably slow,
but string operations don't have to be slow.