Solved

Generic Text driver adds a CR?

Posted on 2000-05-12
23
512 Views
Last Modified: 2010-05-02
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
Comment
Question by:rstone
  • 10
  • 6
  • 6
  • +1
23 Comments
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2805961
Try using:

Format$(X)
0
 

Expert Comment

by:LeReveur
ID: 2805996
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
 
LVL 54

Expert Comment

by:nico5038
ID: 2806562
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
 

Author Comment

by:rstone
ID: 2807277
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
 
LVL 54

Expert Comment

by:nico5038
ID: 2807300
Just a thought:
Try to open the print-file AS BINARY.
0
 

Author Comment

by:rstone
ID: 2807360
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
 
LVL 54

Expert Comment

by:nico5038
ID: 2807425
What happens when you use:
Printer.Print "1" Chr(10) & "2" & Chr(10)

0
 

Expert Comment

by:LeReveur
ID: 2810665
It does appear that the "Generic Text" driver is sending CRLF when it receives a LF.
0
 

Author Comment

by:rstone
ID: 2810711
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
 

Expert Comment

by:LeReveur
ID: 2811603
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
 

Author Comment

by:rstone
ID: 2811886
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 54

Expert Comment

by:nico5038
ID: 2812406
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
 

Author Comment

by:rstone
ID: 2812800
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
 
LVL 54

Expert Comment

by:nico5038
ID: 2814118
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
 

Author Comment

by:rstone
ID: 2814518
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
 
LVL 54

Expert Comment

by:nico5038
ID: 2815108
Just being lazy: Can you zip (the trouble part of it) and mail to my nico5038 hotmail.com account!
0
 

Accepted Solution

by:
LeReveur earned 200 total points
ID: 2817306
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
 

Author Comment

by:rstone
ID: 2818376
Adjusted points from 100 to 200
0
 

Author Comment

by:rstone
ID: 2818377
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
 

Expert Comment

by:LeReveur
ID: 2819199
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
 

Author Comment

by:rstone
ID: 2819355
How can I give a copy of my driver to the user?  That would be great.
0
 

Expert Comment

by:LeReveur
ID: 2875607
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
 

Author Comment

by:rstone
ID: 2876582
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now