Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find & replace 1

Status
Not open for further replies.

Winan

IS-IT--Management
Jan 1, 2002
83
ID
Dear All,

I need to find and replace all chr(10) with "" in a text file, how to do this with VB6?

many thanks in advance

Regards
Winanjaya
 
One quick way would be to use a RichTextBox control. Use the LoadFile method to import the text. Then search the string for the line feeds. When you find one, delete it. Use the RTB SaveFile method when you're done.

I know the RTB control does not have the 64KB size limit like the regular text box, but I'm not sure of the RTB size limit.
 

You can also you Replace function:
Code:
Replace(strSomeText, Chr(10), "")

Have fun.

---- Andy
 
>the 64KB size limit like the regular text box

Just as a matter of interest, this limit is a VB limit, not that of the text box (or 'edit control' as it is better known outside the VB world) itself (and of the old 16-bit Windows versions); an multiline edit control's upper limit under any of the NT-based OSs is actually 4GB-1 , and a single line edit control's upper limit is 2GB-1
 
Well, that gives rise to a few questions, doesn't it? :)

So, does Windows expose the text box control(s) that VB uses as part of the opsys, or do they come from somewhere like MFC? Also, are we saying that VB wanted to preserve backward compatibility with applications written with older versions of VB, and hence around the 16 bit control, so they subclassed the 32 bit control to apply the old limitations?

Bob
 
Hi All,
I just want to replace some chr(10) in a text file and then resave it before I read it line by line..
actually, this is very simple task but I am not sure if there is a simple way for doing this with VB6 (pls correct me If I'm wrong)

any idea? ..

Many thanks in advance

Regards
Winanjaya
 
for additional info, the size of the text file that I want to open is big (more than 150K rows inside)

regards
Winanjaya
 
Winan,
Andrzejek has already shown you how to:

strResults=Replace(strSomeText, Chr(10), "")
 
Yes, I knew but it result to a string, how to send it back to text file?

 
Well, perhaps you'll post your code for reading the text file, and then we can show you a similar method for writing it. There are several ways to do it.

Bob
 
BobRodes said:
So, does Windows expose the text box control(s) that VB uses as part of the opsys, or do they come from somewhere like MFC? Also, are we saying that VB wanted to preserve backward compatibility with applications written with older versions of VB, and hence around the 16 bit control, so they subclassed the 32 bit control to apply the old limitations?
VB superclasses a number of system global window classes. The Textbox (Classname = ThunderTextBox) is a superclass of the Windows edit control (Classname = Edit).

And yes, they failed to update a number of controls that used Integer parameters when VB transitioned to 32-bit (almost certainly because they wanted programs written under 16-bit VB4 to be easily ported to 32-bit VB4 without any further intervention, and have not bothered really updating the core controls since that time ...)
 
>VB superclasses a number of system global window classes

I'm perceiving that VB's TextBox inherits the Edit box as a starting point, which would make it a subclass in the semantics with which I'm familiar. Am I perceiving wrong, or do we have different semantics, or are we talking about different things?

Integer parameters. Aye, there's the rub....
 
The WLText control in the Microsoft Windowless Controls 6.0 library doesn't have this limitation.

It does have other issues however. First, the Lightweight Controls don't support DDE. Secondly, they're Unicode-enabled which can be both a blessing and a curse. Thirdly, if run under WinXP in a program with an XP Styles manifest the WLText control has the wrong symbols displayed for the scrollbar arrows.

The big headache I've seen with the WLText control though is erratic behavior when using the SelLength, SelStart, and SelText properties.

For example storing a 20,000 char String into a WLText, then setting SelStart to 20,000 and setting SelText to the 20,000 char String value again seems to result in only about the 1st half of the big String getting inserted (appended).
 
Well maybe I was just using WLText incorrectly?

The last time I was playing with those controls I was hoping for a better to way to handle things like framed option buttons (an XP Styles issue). Sadly the results were worse than using the regular ones.

The real answer is probably a 3rd party library designed to provide XP-Styled replacements for many of the intrinsic controls.
 
Yeah, and now we have Vista....I wouldn't put any money into marketing controls for a given Microsoft opsys, unless I had enough money to keep retooling them for each new opsys that Microsoft puts out.
 
>The Textbox (Classname = ThunderTextBox) is a superclass of the Windows edit control (Classname = Edit)

I also believed the same till yesterday. But in context of recent discussion about subclassing in this thread and thread222-1364428, I found the following article:

Subclassing & Hooking with Visual Basic

It states:
All VB form and control classes are superclasses of the VBBubbleRT6 class, which is also a superclass of the ThunderRT6Main class.

It also states that all VB controls and forms share the same window procedure (which can be varified using Spy++), as they are all derived from the same base class, VBBubbleRT6, as mentioned above.

In this way, VB controls (like TextBox) are not direct subclasses (or superclasses) of windows standard controls (like Edit control).

One question arises at this point. If all VB forms and controls are derived from VBBubbleRT6 which is derived from ThunderRT6Main, and if all of them share the same window procedure, than how do the messages belonging to individual windows are routed to actual window procedures? How does VB identify and distinguish different controls? By looking at their class names or what?

This all sounds too confusing.
 
Hi Winanjaya,

you could do it like this:
Code:
 Dim fso, tso, tmp
Set fso = CreateObject("Scripting.FileSystemObject")
filename="[here goes the full path to your file]"
Set tso = fso.OpenTextFile(filename,1,false,0)
[b]tmp=tso.readall
tmp=replace(tmp, chr(10),"")
tso.Write(tmp)[/b]
tso.Close
set tso=nothing
set fso=nothing
;-)

Hope this help.

Cheers,
MiS

[blue]Help us, join us, participate
IAHRA - International Alliance of Human Rights Advocates[/blue]
 
thanks a lot!

regards
Winanjaya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top