Full Version: sending hex code to printer without "
UtterAccess Discussion Forums > Microsoft® Access > Access Modules
dkmarsh
I have an application that needs to send a hex code to a printer. The problem I am having is that it is sending a hex 22 charactor (which is a ") at the start and end of string.

How can I stop it sending the hex 22 at the start and end of the string ?

The variable is defined as:

Public g_open_code As String

g_open_code = Chr$(27) & Chr$(112) & Chr$(0) & Chr$(5) & Chr$(80)


The code that issues the command is:

Open w_strportname For Output As #w_freefile

Write #w_freefile, g_open_code

Close #w_freefile
datAdrenaline
The behavior you are seeing is a feature of the Write # statement. It was set up that way to work in conjuction with the Input # statement. The Input # statement can enterpret its data as a specific format ... and if the data is a string, Write # will put dbl-quotes around it. To prevent this from happening, I beleive you can use the Print # statment instead.

*Note: I am unable to verify this at the current moment, so ... I may be a little off, I have not used the Write# in quite some time ... but I am virtually certain the Print # statement will do what you want to do.
strive4peace
Hi Brent,

oh,,,, can you use the Write or Print statement to send escape sequences to a printer??? I have been looking for a way to do this!
datAdrenaline
Try something like this:

CODE
Public Sub Foo()

    

    Dim x As Integer

    Dim intChannel As Integer  'The channel to communicate thru

    Dim strDestination As String  'PORT or Filename to interact with

    

    For x = 1 To 511

        Close #x

    Next x

    

    intChannel = FreeFile()

    strDestination = Printer.DeviceName 'This is the windows default printer, special characters

                                        'will cause probs ... I think.

    'strDestination = "LPT1"   'the parallel port

    

    Open strDestination For Output As #intChannel

        'Sample "messages" to the printer

        Print #intChannel , [the esc character and code]

        Print #intChannel , "TESTING 12345"

        Print #intChannel , Chr(12)

    Close #intChannel

    

End Sub


NOTE!! ... This is AIR CODE ... I don't have a printer hooked up to test it!!
strive4peace
Hi Brent,

thank you much, my friend! I didn't test it yet either, but saved it and next time I want to do that, I will!
dkmarsh
Thanks so much. I changed the write to a parint and the " are now gone.

However, I am having a problem where it is adding a carridge return, then line break (hex 0D 0A) at the end of the string.

This mans that instead of pruinting "" it is pritning a blank line.

How can I make it just send the specified hex string ?
datAdrenaline
... Real short on time ... but investigate the use of:

Put #

I think that is just a raw send and does not get any "extra" codes/chars appended.
BuddyM
Hi Brent,

I found this thread extremely helpful with my simular problem I was having. Thank you! Just a quick question...

I have a printer shared over the network that I need to print to. I have used the code as described above. Works perfectly when I have the printer set up local on LPT1 however, it seems to have a problem when working over a network.

I have got the name as shared on the network in the code i.e.

CODE
Set Application.Printer = Application.Printers("SurvOBPr")


still no glory though, what am I missing here?
datAdrenaline
Hello Buddy ...

Are you printing out a Report ... or are you trying to write directly to the printer port like the sample code is? ....
BuddyM
I'm printing straight to the printer port like the sample code. The problem is it is not picking up the printer over the network. I have done a test page on the network from one of the PC's which will be using the database. Printer setup is fine. I need the code to pick up the network printer which is not local on that PC.

I am hoping there is code which will enable me to do this.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.