Results 1 to 3 of 3

Thread: Using multiple printers

  1. #1

    Thread Starter
    Member
    Join Date
    May 2018
    Posts
    37

    Using multiple printers

    Once again, more tinkering with our good old VB6 EPOS system. We use two printers on each workstation, a slip printer for receipts and an A4 printer for everything else.

    At present, there is nothing in the program to know which printer to use, everything just prints to the default printer and the user manually changes the default in Control Panel to get the output of the correct printer. This was never ideal, but was a simple process to train the users on in Windows 7 where switching printers is very easy.

    We are looking at migrating to Windows 10 where the default printer settings are a bit more hidden and so I'd like to take the opportunity to develop the program to know what is supposed to print where and end users having to manually switch.

    I do remember writing an Excel macro years ago which could switch printers, but this relied on knowing the name of the printer in Windows. Ensuring that every workstation has the printers named exactly the same would be too easy to break and I can already see it taking up a lot of support time.

    I was hoping to do something a bit more abstract where I could add definitions for the slip and A4 printers which can be set within the program. The idea would be to add a UI control for 'slip printer' which would launch the common print dialogue, then the required printer would be selected and the program would store this setting as the slip printer. After that all receipts would simply be sent to the 'slip printer' and the program would look up what printer it has set for that. There would then be another setting implemented on the same lines for the A4 printer.

    This would make it easy to deal with the printers being named differently across different machines.

    Any ideas on how to start with this (or if it's even possible?)

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,239

    Re: Using multiple printers

    I typically store the printer(s) to use in an ini file. In my case it is often a report printer and a label printer.
    I generally do not bother with the print dialog and instead have a settings screen in the program where the user can assign the printer for each task.

    Using the printer object in VB you can set the VB printer to any printer at any time so the process is fairly simple.
    Here are some small snippets from a program I did a while back that uses two different printers based on which stockroom the item is in.

    In a module the printer vars are defined
    Code:
    Public Printer1 As Printer
    Public Printer2 As Printer
    Public Printer1Name As String
    Public Printer2Name As String
    The printer name vars are read in from an ini file at start up.

    There is a routine that I use to make sure that the printer is assigned and valid, Here is a small section of that routine for example
    Code:
    For Each prn In Printers
            If UCase(prn.DeviceName) = UCase(Printer1Name) Then
                Set Printer1 = prn
                FoundPrinter1 = True
                Exit For
            End If
        Next
        If FoundPrinter1 Then
            Label2.Caption = Printer1.DeviceName
            Label2.ForeColor = vbBlack
        Else
            Label2.Caption = Printer1Name & " not available!"
            Label2.ForeColor = vbRed
            NotReady = True
        End If
    Below is a snippet from the code that does the actual printing


    Code:
                   If StockRoom = 1 Then
                            Set Printer = Printer1
                            Printer.Print TicketData
                            Printer.EndDoc
                            TicketData = ""
                        Else
                            Set Printer = Printer2
                            Printer.Print TicketData
                            Printer.EndDoc
                            TicketData = ""
                        End If

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,941

    Re: Using multiple printers

    make sure to have some method for the user to switch to another printer if one fails, no ink, no paper or any other reason, or is replaced, new printer would probably have different name
    if you application hss a database then you can use a table to store the printer settings per form
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width