VB2013 Code does not recognize hieght of a label

Posted on 2014-12-06
Medium Priority
Last Modified: 2014-12-07
Hello Experts,
The following vb2013 code prints ONE label ans stays right where the last line was printed,
How can I make it jump to the next label ?
not leave a whole blank label, but just go to next label.

Right now its not leaving a blank label, just stays in the las printed line and does not jump to the beggining of the next label. which is what I need order to send the next label with different data.



Public Class Form1

    'Button1 starts printing of a single-page document with barcode.
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim pd As New Printing.PrintDocument
        pd.PrinterSettings.PrinterName = "ZDesigner GC420d (EPL)" '-- Uncomment this to select a specific printer.

        AddHandler pd.PrintPage, AddressOf PrintHandler
        RemoveHandler pd.PrintPage, AddressOf PrintHandler
    End Sub

    'This Sub constructs a printable page.
    Private Sub PrintHandler(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)
        Dim barcode = AxStrokeScribe1 'This name is assigned to the barcode ActiveX by default.'To check which name the ActiveX actually has, select the ActiveX, press Alt-Enter and look for the Design group in the Properties box.
        barcode.Alphabet = enumAlphabet.CODE128 'Change this to produce barcode of the desired type.
        barcode.CtlText = "1234ABCD" 'This text will be stored in the barcode.

        Dim img As Image
        img = barcode.GetPictureHandle(enumFormats.EMF, 30, 15) 'Generates a barcode picture, 50x30mm.
        If barcode.Error Then
        End If

        Dim ag = args.Graphics

        ag.PageUnit = GraphicsUnit.Millimeter
        ag.DrawString("1234567890QWERTYUIOP1234567890XZCVBNMNBV", New Font("Arial", 8), Brushes.Black, 0, 1) 'A text label near the barcode
        ag.DrawString("1234567890QWERTYUIOP1234567890XZCVBNMNBV", New Font("Arial", 8), Brushes.Black, 0, 4)
        ag.DrawString("1234567890QWERTYUIOP1234567890XZCVBNMNBV", New Font("Arial", 8), Brushes.Black, 0, 7)
        ag.DrawImage(img, 1, 10) 'Position of the left-top corner of the barcode relatively to the left-top corner of the page (millimeters).

        args.HasMorePages = False 'We print only one page each time the Button1 is pressed.
    End Sub
End Class

Open in new window

Question by:RGuillermo
  • 2
  • 2
LVL 40
ID: 40484715
Do you want to print many copies of the same label, or print different information on each label?

Are you printing on label sheets that have many columns or on a 1 column label printer?

Author Comment

ID: 40485053
I am printing in a one column label zebra printe GC420d
and most of the time I need to print diferente labels.
But at the end of the month I may need to repeat a few labels almost a hundres copies.
LVL 40

Accepted Solution

Jacques Bourgeois (James Burger) earned 2000 total points
ID: 40485085
I am kind in a hurry right now (Saturday evening here in the Montreal area), so I do not have time to give you sample code, but here is the basic rundown.

args.HasMorePages = False does not really mean a page, it means that you have nothing else to print and it stops the printing. Usually, you set it to True when a whole page has been printed. This triggers the event again, and you continue printing on the following page from where you left on the previous run of the event.

It's not evident from what I see with a quick search, but the GC420d looks like one of these printers that have a continuous feed of labels from a roll. When you print a series of labels such a printer, you forget about the notion of page. The "page" is a single label if you print them one by on, your whole series if you print many of them in the same run.

If you print one label at a time, add an extra DrawString with a space as text, specifying a Y parameter that will have the right value to bring you to the beginning of the following label before you set HasMorePages to False. You will then be ready for your next label.

If you print a series of labels, the trick is to first have the data ready in a variable declared at the class/form/module level so that it is available in the event. If you need to print different labels, store the data in a collection or array variable.

You then enclose your series of DrawString + DrawImage in a loop. Each run in the loop will print one label. And instead of using fixed values for the vertical position (1, 4, 7 and 10) , use multiples of the loop counter multiplied by the height of 1 label plus the space between labels. If you loop with something like For x=0 to 10, then use 1+14*x, 4+14*x, 7+14*x and 10+14*x). You will have to try with different values for the 14. It needs to be adjusted for the type of labels that you use.

Because the loop runs before the HasMorePages=False command, it will continue printing as long as you loop. And since you are increasing the Y position in each loop, it will just go lower down on the ribbon that holds the labels.

Author Closing Comment

ID: 40485465
thank you Jacques,
That was clear enough
If you have time send me a Little code just in case,

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This article describes and provides a custom-made tool I wrote to give businesses a means of identifying commercial music content, without having to expend too much effort. Business recordings are easily identified from possibly illegal music files …
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…

586 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