Print with no line feed

  • Thread starter gimme_this_gimme_that
  • Start date
G

gimme_this_gimme_that

I have:


Sub Write2()
Open "C:\output.txt" For Output As #1
Print #1, "hello"
Print #1, " world"
Close #1
End Sub


Which creates a file that looks like

hello
world

Is there a way to tell Print not to add the line feed - so I can get

hello world

Thanks.
 
D

Dave Peterson

Sub Write2()
Open "C:\output.txt" For Output As #1
Print #1, "hello world"
Close #1
End Sub

or maybe...

Sub Write2()
Open "C:\output.txt" For Output As #1
Print #1, "hello";
Print #1, " world";
Close #1
End Sub
 
R

Rick Rothstein \(MVP - VB\)

Did you try either of what Dave posted? If you look carefully at the second
one, you will see a semi-colon after the Print statement argument... that
tells the Print statement to suppress the line feed (actually, it is a
carriage return followed by a line feed the Print added to your output and
it is this combination that the semi-colon suppresses). By the way, this is
covered in the help files for the Print# Statement (which I am guessing you
didn't read).

Rick


No silly.

Is there a way to tell Print not to add the line feed?
 
D

Dave Peterson

Thanks, Rick!

Rick Rothstein (MVP - VB) said:
Did you try either of what Dave posted? If you look carefully at the second
one, you will see a semi-colon after the Print statement argument... that
tells the Print statement to suppress the line feed (actually, it is a
carriage return followed by a line feed the Print added to your output and
it is this combination that the semi-colon suppresses). By the way, this is
covered in the help files for the Print# Statement (which I am guessing you
didn't read).

Rick

No silly.

Is there a way to tell Print not to add the line feed?
 
L

Luke Alcatel

I think it's a little harsh to scold the OP because he didn't RTFM. Here's
what my help file says:

Use a semicolon to position the insertion point immediately after the last
character displayed.

and

Multiple expressions can be separated with either a space or a semicolon. A
space has the same effect as a semicolon.

I don't think it's at all clear that the semi-colon accomplishes what the OP
asked. I recall that it took me some time to figure out how to do exactly
what the OP wanted to do. I don't know about others but I think this is
just one example of frequently obfuscated MS documentation.

Luke
 
G

gimme_this_gimme_that

Thanks Dave, Rick and Luke.

Yes, I didn't notice the semi-colon on Dave's first follow up post.

This was what I needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top