What escape sequences to use for positioning several lines of text?

Good Afternoon,

I am in the process of developing a Cheque Printing application in VB.Net and will be using an  “OKI Microline 390 Turbo” as my dot matrix printer on Windows 7 32-Bit.

I’ve been using several escape sequences to control the pitch, font type etc. What I am stuck on now is the positioning of things. As I am printing information on a cheque, I need specific information to go in certain positions but cannot figure out how to accomplish this.

I was able to use tabs to position things, but have realized that this is not going to work, as depending on how many characters are in the text will make the position go off and push the tabs out of place.

Sample code here:

Public Const eClear As String = Chr(27) + "@" + Chr(27) + Chr(107) + "2"
Public Const eNmlText As String = Chr(27) + "!" + Chr(0) 
Public Const eHTAB As String = Chr(9)

Public Sub PrintBody()

        Dim N2WResult As String

        N2WResult = AmountInWords(txtMAmt.Text)

        Print(eClear + eHTAB + eHTAB + eHTAB + eHTAB + eHTAB + eHTAB + eHTAB + "   " + eNmlText + txtMChqNum.Text + vbCrLf + vbCrLf + vbCrLf)
        Print(eHTAB + "   " + eNmlText + DateTimePickerM.Text + eHTAB + "    " + eSmlText + N2WResult + vbCrLf + vbCrLf)
        Print(eNmlText + txtMPayTo.Text)
		
...etc

Open in new window


I’ve found a list of escape sequences here: http://whitefiles.org/b1_s/1_free_guides/fg2cd/pgs/c03c_prntr_cds.htm and have also downloaded the manual for my printer which has the Epson escape sequences as well. But I need "EXAMPLES" on how to accomplish the positioning of things. I've been all over the Net, and have been able to find the sequences but cannot find examples on how to use them.

After doing some reading I think what I am looking for is to set a "Horizontal/Vertical Absolute Position", which I think means the printer carriage will go to that specific position and start to print there. So I'm guessing I will need a few of them to ensure the data prints exactly where i want it to on the cheque.

Can someone let me know if this is the way to go? And if so to please provide some EXAMPLES of it in use?

Kindly advise.

Regards,
N
LVL 1
KevinInformation TechnologyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hdhondtCommented:
You can use the following commands (from your link):

27 36 n1 n2              Set absolute dot position to n1+(n2*256) in
           ESC $ n1 n2   60th of inch

27 66 n1 n2 … 0          Set vert tabs, n1, n2 …, 1 to 255 in ascending order
           ESC B n1 n2 … NUL

After the 2nd command you then need to use the HT character to get the carriage to the tab stop(s).
KevinInformation TechnologyAuthor Commented:
Thanks for your response hdhondt but I need a bit more explanation, as I am still not following.

I do not understand how to obtain 'n1' and 'n2'. I see the formula but cannot understand where the 256 is coming from in the formula, is this from one side of the paper to the other?

And same thing with the vertical, where is the 255 coming from?

When you say "After the 2nd command you then need....." Which 2nd command are you referring to?

Sorry, but this is very very new to me, please be as specific as possible so that I can have a better understanding.

Kind Regards,
N
hdhondtCommented:
I've edited some mistakes in this comment. Below is the corrected version:

n1 and n2 are just numbers, to indicate the print position.

Let's take the first command as an example. Assume we want to start printing at 6" from the left margin.

6" = 360 (in 60ths of an inch.)

The command starts with characters 27 36 (decimal). It is then followed by 2 characters that represent that position. We have:

n1+(n2*256) = 360

Hence, because 1*256 + 104 = 360, we have:

n2 = 1 and n1 = 104

So, the entire sequence becomes characters 27, 36, 104, 01 (decimal). In this the only printable characters are 36 ($) and 104(h).  In your code, the string would become

Chr(27) + "$" + "h" + chr(1)

Of course, these numbers may change, so you may have to use variables for them.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

KevinInformation TechnologyAuthor Commented:
Morning hdhondt,

I have a better understand but am still very stuck with the calculation, math not being my strongest subject.

I was able to find this URL (http://www.uktsupport.co.uk/epson/impact/esc2gui.htm) which gave step by step examples on how to calculate the positions for the "Absolute Vertical Position", no horizontal positions unfortunately.

But still I am having troubles. With your example of 6" I understand the calculation.

6" = 360 (in 60ths of an inch.)

1. 1 * 360 = 360
2. 360 / 256 = 1 (the whole number (n2))
3. 360 - 256 = 104 (the remainder (n1))

However when i put it in my code the position is at '6.4 inches' instead of '6 inches'.

When I attempt to do the same thing with say 4" it doesnt appear to work.

4 * 360 = 1440
1440 / 6 = 240

4" = 240 (in 60ths of an inch.)

1. 1 * 240 = 240
2. 240 / 256 = 0 (the whole number (n2))
3. 256 - 240 = 16 (the remainder (n1))

As the result puts the position at '1.5 inches' instead of '4 inches'.

Do you mind to be as basic as possible with how to calculate the position? Think of me as a kid just learning math.

Much appreciated for your all your help.

Kind Regards,
N
KevinInformation TechnologyAuthor Commented:
Hi hdhondt,

Ok so looking at this more, I see that i was measuring the distance incorrectly. As before I was taking a ruler and measuring from one side of the paper to the other and this is why 6 inches from your example seemed a little off.

Now I am measuring from the left margin and the 6 inches is matching up.

I was able to calculate 5 inches as well, doing the below:

5"
5 * 60 = 300
300 / 256 = 1 with a remainder of 44
n1 = 44
n2 = 1

However, I am still not sure on why 4 inches is not working.

This is my calculation:

4"
4 * 60 = 240
240 / 256 = 0 with a remainder of 16
n1 = 16
n2 = 0

Now I've that from your first example for 6 inches those values for 'n' relate to the ASCII Character Set . This is why '104' was 'h'.

With my results from calculating 4 inches, the values of 'n' being 16 and 0, doesnt have any value in the ASCII character set. '0' being 'NUL' and '16' not having any value at all.

ascii.png
So how would I be able to set this position if the values for 'n' dont exist.

Kindly advise.

Regards,
N
hdhondtCommented:
You need to work out n1 and n2 so that

n1 + n2*256 = inches * 60  (i.e. displacement in 60ths of an inch)

As 240 is less than 256, we have for 4":

240 = 240 + 0*256

Hence n1=240 and n2=0

What you call the "value" of the character is just a conventional name for it. For example, 13 is a Carriage Return (CR). Your table does not show all those names. 16 is in fact a DLE character (data link escape). However, these names do not matter; what is important is the decimal (or hex, binary...) value of the character.

For a full ASCII chart see http://www.asciitable.com/

Note that the ASCII table only does up to 127, as old computers only used 128 characters (7 bits). A byte is 8 bits and can have values up to 255 (that's where the 256 in the calculations comes from).
KevinInformation TechnologyAuthor Commented:
hdhondt, I apologize for the delay in getting back to you, I have been out ill.

Thank you very much for all of your assistance with this problem. I understand now and have put all in place, so it's working like it should now.

Kind Regards,
N
hdhondtCommented:
Great. Thanks for the points, nobushi
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Printers and Scanners

From novice to tech pro — start learning today.