Solved

VB2013 Code does not recognize hieght of a label

Posted on 2014-12-06
5
141 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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now