Print # problem

  • Thread starter Thread starter Janet Ciegler
  • Start date Start date
J

Janet Ciegler

In VBA code, I'm using a series of "Print #" commands to write to a text
file. Somewhere I remembered that putting a semicolon on the end of a
command would cause the subsequent output to be concatenated after this,
and that omitting the final semicolon would create a new line of output.
But today that doesn't seem to be working. What have I forgotten?
Here's a sample line that I want *not* to start a new line:
Print #3, Tab(15); Valu(19, i);
Thanks in advance! Jan
 
What you have looks ok. Either something else is wrong in your code, or
perhaps the values in that array have a crLF in the text.
 
I'd love to do that, Larry, but ever since I got a new Windows XP
computer two years ago, and installed Access 2000 from my original CD,
the Help doesn't work. All I get when clicking on the Help button is a
welcome screen from MS Office Help describing all the good things that
are there no longer. And my 2-inch-thick VBA book barely mentions Print.
Jan
 
Here's a link to the Print # topic in the MSDN library ...

http://msdn.microsoft.com/library/en-us/vbenlr98/html/vastmPrint.asp

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Thanks for responding, Larry, Albert, and Brendan, but unfortunately
nothing has worked. The online help is good to know about, but doesn't
say anything about how not to start a new line. I don't have any CR/LFs
in my data. Oh, well....
Jan
 
Well, it does, but it is rather confusingly worded ...

<quote>
Use a semicolon to position the insertion point immediately after the last
character displayed
</quote>

What they mean is ...

Public Sub DemoPrint()

Debug.Print "First line without a semi-colon"
Debug.Print "Second line without a semi-colon"
Debug.Print "Third line with a semi-colon";
Debug.Print "Fourth line with a semi-colon";

End Sub

Result of calling this sub from the Immediate window ...

demoprint
First line without a semi-colon
Second line without a semi-colon
Third line with a semi-colonFourth line with a semi-colon

While I'm using Debug.Print here for demonstration purposes, Print # works
in exactly the same way.

The best source for documentation and examples using Print # and related
commands is old books on QuickBasic or QBasic - very little has changed in
VBA as far as these I/O commands are concerned. Possibly your local library
might have some of these old books.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Think I’ve solved my own problem. The Tab character causes new lines,
and removing that permits printing successive records on the same line:
Print #3, Valu(19, i);
Makes sense, because if I tell it to go to position 15, that's exactly
what it does.
 
Thanks, Brendan, for all your effort! Yes, we have a good library which
likely has one of those books. Jan
 
Sorry, Janet, but no, that's not it. Tabs don't start a new line. See below
....

Public Sub TestPrintTab()

Debug.Print Tab(15); "some text", "I bet this doesn't print on a new
line";

End Sub

Result of calling this in the Immediate window ...

testprinttab
some text I bet this doesn't print on a new line

Could it be that the data you're printing after the tab is simply too long
to fit on the line?

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Brendan, I guess I neglected to mention that my code was in a loop, so
that the first iteration probably continued that line as intended, but
the next iteration including Tab(15) went to the 15th position before
printing the next text, and therefore had to be on the next line.
Anyway, when I removed the Tab command, now the items line up on a
single line as intended.
Thanks for all your insight!! Guess I'll have to try Debug.Print sometime.
Jan
 
Hi Janet,

The Acc97 help didn't indicate that a trailing semicolon would avoid the
creation of the end of line.

What I've done in situations similar to yours is to accumulate interim
results into variables and then Print the lot in a single Print # statement.

To the best of my recollection the semicolon only meant that the immediately
following output would be concatenated rather than written to tab stops.

HTH
 
Hi, Larry,

Accumulating into variables is a great idea, and thanks for suggesting it!

Jan
 
Back
Top