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!

Trouble with CHR(13)

Status
Not open for further replies.

SkennyR

Programmer
Mar 7, 2004
157
US
I know this is probably very simple, but Im having a problem when trying to replace chr(13) in a string with a comma (",").
The string is coming from a text box set to multiline.
here is an example:

Dim x as integer
Dim a as string
Dim b as s tring
a =text1.text
for x= 1 to len(a)
if mid(a,x,1)<>chr(13) then b=b+mid(a,x,1)
if mid(a,x,1)=chr(13) then b=b+","
next x
open "c:\text.tst" for output as #1
write #1, b
close 1

If I look at the string b, I dont see any chr(13), but
if I open the file "c:\text.tst" with wordpad, the string is seperated into multiple lines, as if the chr(13) is still in there.
What the heck am I doing wrong? This should be fairly simple.
Thanks for your help.
 
Use the print # statement.

Also, you can use the replace statement to do the whole thing at once.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
MsgBox Replace(Text1.Text, vbCrLf, ",")


// This will do the job. Chr(13) is not right.
// You needed Chr(13) + Chr(10) (= vbCrLf)
 
Thanks! I knew there had to be an easy way to do this, but I have a bad habit of not seeing the forest for the trees.
Once again, thanks to the both of you!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top