Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Escape Sequence in VB

Posted on 1999-07-11
Medium Priority
Last Modified: 2008-03-17
How do you issue an Escape Sequence in VB5 to control a printer ? I am trying to issue   ESC "d" 0   to control a paper cutter in a small ticket printer. I have tried   printer.print chr$(27)+chr$(100)+chr$(48)  but the characters "d0" actually got printed out which shouldn't have been and the ESC control code have not functioned. Can anyone help ??
Question by:tinson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 22

Accepted Solution

ture earned 100 total points
ID: 1523594

Try something like this:

  Open Printer.Port For Binary As 1
    Put #1, , Chr(27) & "d0"
  Close 1

Ture Magnusson
Karlstad, Sweden

Author Comment

ID: 1523595
Hi Ture,
Thanks for your reply!
The code works fine on its own, it does the job, no problems. However, if I insert it into my code as follows, I get "Run time error 75 - Path/File access error", I can't see what the problem is, can you help ?

My Code:

Private Sub Command1_Click()

' Print Text
Printer.ScaleMode = 6
Printer.FontName = "SwitzerlandNarrow"
Printer.FontItalic = False: Printer.FontBold = False
Printer.FontSize = 10
Printer.Print "test"

' Cut Paper
Open Printer.Port For Binary As 1
   Put #1, , Chr(27) & "d0"
Close 1

End Sub
LVL 22

Expert Comment

ID: 1523596

I'm not sure... Perhaps it's a timing error - your previous interaction with the printer is not quite finished.

If you add a msgbox just before 'Cut Paper', so that you can make the procedure wait a little - Does that help?

Then you can try something like this to keep trying until the port is can be opened.

  f = FreeFile
    Open Printer.Port For Binary As f
  Loop Until FreeFile <> f
  Put #f, , Chr(27) & "d0"
  Close f


Author Comment

ID: 1523597
Hi Ture
Thanks for your prompt reply.
I think you are right, it is a timing error.
I have done what you suggested, but still no good because the printer is slow in responding to the printing instructions; It works only if the user issue the cutting ESC sequence via a MessageBox after everything is printed. But problems occured when I confirm 'OK' in the MessageBox  to trigger the cutting before the actual printing is finished.
What is the VB code for checking the printer has finished printing ? If I can first check the printer has finished printing, than issue Cutting ESC instruction in the Code, I think the problem can be solved.  What do you think ?

Thanks yet again for your helpful advice.

LVL 22

Expert Comment

ID: 1523598

I see that you have posted a new question regarding how to check if the printer has finished printing. That is good, because I haven't really done this before. Visual Basic works nicely when you depend on printer drivers, but when you wish to send control codes directly to the printer you need some special procedures.

I have found some information on 'sending raw data' to a printer using Windows API calls and Visual Basic. I'm not good at API calls, but I really think that it is the way to solve your printing problem. Read about it at:


Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

705 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