Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 619
  • Last Modified:

Generic Text driver adds a CR?

I'm trying to print to a thermal label printer.  It takes text commands, so I normally just Open LPT1 for Output and print.  It works fine.  I now need to use a Generic Text driver, but when I do, a Carriage Return gets added after my first line!  My code is this:

Open LPT1 for output as #1

For X = 1 to 10
   Printer.Print Trim(Str(X))
Next X
Printer.EndDoc

When I set my default printer to my generic text driver, I get this:

1CRCRLF2CRLF3CRLF4CRLF5CRLF6CRLF7CRLF8CRLF9CRLF10CRLF

CR is a Hex 0D and LF is a Hex 0A.  Basically, I'm getting an extra CR at the end of myfirst line.  What's going on and how can I stop it?  I'm running this under Windows98.  Will it be different under Windows95, Windows NT, or Windows 2000?
0
rstone
Asked:
rstone
  • 10
  • 6
  • 6
  • +1
1 Solution
 
GivenRandyCommented:
Try using:

Format$(X)
0
 
LeReveurCommented:
This seems like a problem I had at one time when using the Generic Text driver. I'm thinking that I had to end the PRINTER.PRINT statement with a semicolon and explicitly concatenate any carriage returns and line feeds that I wanted.

So, if you want one carriage return:

Printer.Print Trim(Str(X)); Chr(13);
0
 
nico5038Commented:
After each print a CR is written unless you use a trailing ";"
I think it's better to keep printing lines, thus use:

Open LPT1 for output as #1

DIM hlpLine as String

For X = 1 to 10
   hlpLine = hlpLine & (Str(X))
Next X
Printer.Print hlpLine
Printer.EndDoc

Nico
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rstoneAuthor Commented:
When I try to put everything into a string, I still get the same result:

Printer.Print "1" Chr(13) & Chr(10) & "2" Chr(13) & Chr(10)

etc.

I still get:

1CRCRLF2CRLF3CRLF4CRLF5CRLF6CRLF7CRLF8CRLF9CRLF10CRLF
0
 
nico5038Commented:
Just a thought:
Try to open the print-file AS BINARY.
0
 
rstoneAuthor Commented:
I'm not opening the print file, though.  If I use OPEN "LPT1" for Output as #1, it works fine.  I need to use the print driver, that's why I need to use Printer.Print.
0
 
nico5038Commented:
What happens when you use:
Printer.Print "1" Chr(10) & "2" & Chr(10)

0
 
LeReveurCommented:
It does appear that the "Generic Text" driver is sending CRLF when it receives a LF.
0
 
rstoneAuthor Commented:
It's interesting.  When I try:

Printer.Print "1" Chr(10) & "2" & Chr(10)

It shows up as a CRLF.  Same thing when I try:

Printer.Print "1" Chr(13) & "2" & Chr(13)

I could live with this if it didn't put the extra CR on the first line. Is there a replacement Generic Text driver somewhere?  How hard is it to write one?
0
 
LeReveurCommented:
The last time that I actually played with the "Generic Text" driver was probably with Windows 3.1 but I may have also worked with it under Windows 95. It's difficult to remember as the company employed me at the time had not yet converted to Windows 95 but I had it installed on my PC.

Unfortunately, I don't have access to the Windows NT CD at work to install the "Generic / Text Only" driver. However, I do remember that there were configuration options with the driver to set things such as "Add LF after CR", etc. I wish I could give you explicit instructions.
0
 
rstoneAuthor Commented:
I can't find anything configurable in the driver that looks like it would do that.  I have paper source set to Continuous, Letter size, no separator page.
0
 
nico5038Commented:
rstone,

Both:
Printer.Print "1" Chr(10) & "2" & Chr(10)
and
Printer.Print "1" Chr(13) & "2" & Chr(13)
work.

Why not add the first line as a string in front like:
Printer.Print strLineOne & Chr(10) & "1" & Chr(10) & "2" & Chr(10)

BTW did you search for the specific thermalprinter driver?

I use a label printer but I just send a straight format Form to it in the right size (from-size) and have no problems.
You could display one or more text fields with the escape codes added to it.

Giving some idea's ?

Nico
0
 
rstoneAuthor Commented:
It doesn't seem to matter what I do.  No matter what I always end up with an extra CR at the end of the first line.  I have tried what you suggested about putting it all on the same line and it still happens.
0
 
nico5038Commented:
Again but slightly different:

Why not add the first line as a string in front like:
Printer.Print strLineOne & "1" & Chr(10) & "2" & Chr(10)

In other words: did you perhaps included a CHR(13) in strLineOne ?

I'm always supersticiuos !

Nico
0
 
rstoneAuthor Commented:
There's no way that I'm including the extra Chr(13) in my string.  I've tried everything I can think of.

I tried what you just suggested and made sure that I'm not including a CR, and the extra CR still appears.  Could you check it out on your system?  I've run the same code from work and home and I get the same result.
0
 
nico5038Commented:
Just being lazy: Can you zip (the trouble part of it) and mail to my nico5038 hotmail.com account!
0
 
LeReveurCommented:
I checked out the "Generic / Text Only" driver at home. It must have been Windows 3.1 where I was able to control the handling of CR and LF. However, I have an idea which has a good chance of working. Modify the properites of the "Generic / Text Only" printer driver. At the bottom of the second tab, you can define certain characters. Define one of the characters (251, for example) to use CR and another (252, for example) to use LF. You might have to enter the LF by holding the Alt key down while typing 010 on the numeric keypad. Likewise, for CR using 013. Then change your code to print CHR(251) instead of CHR(13) and print CHR(252) instead of CHR(10). This will eliminate any chance that the driver is messing around with CR and LF.
0
 
rstoneAuthor Commented:
Adjusted points from 100 to 200
0
 
rstoneAuthor Commented:
OK, that actually worked.  Is there any way for me to modify that section programatically?  The point of using the Generic Text driver is so the the end user can easily install it.
0
 
LeReveurCommented:
There probably is a way to modify that section programatically using the Windows API. Unfortunately, I don't have that information at hand to give you the code. However, there are a couple of options for you. The first option is to write an installation document that includes screen prints for clarification of the instructions. The second option is to further modify your working "Generic / Text Only" driver by renaming it to something more meaningful. Then you can give a copy of your modified driver to the user to install.
0
 
rstoneAuthor Commented:
How can I give a copy of my driver to the user?  That would be great.
0
 
LeReveurCommented:
Sorry I haven't been able to respond right away. After looking into how to copy the driver, it seems more involved than I had originally thought. You can export part of the registry but I'm not familiar with which sections would need to be exported. I would hate to tell you what sections to export only to miss something. I hope you can get help from someone else on this aspect.
0
 
rstoneAuthor Commented:
I have actually figured out a solution to my problem.  I forgot where I got it, but I found some VB code that uses the Windows API to open a driver and print raw data to it.  Now it doesn't matter what actual driver is being used because the raw data just goes to where the driver is pointed, but the driver doesn't interpret it.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 10
  • 6
  • 6
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now