Solved

VB2013 Code does not recognize hieght of a label

Posted on 2014-12-06
5
145 Views
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.

Regards,



Imports STROKESCRIBELib

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
        pd.Print()
        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
            MsgBox(barcode.ErrorDescription)
            Return
        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

0
Comment
Question by:rguillermo
  • 2
  • 2
5 Comments
 
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?
0
 

Author Comment

by:rguillermo
ID: 40485053
Jacques.
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.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 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.
0
 

Author Closing Comment

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

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

792 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