dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Getdefaultprinter problems

  1. #1
    Join Date
    Nov 2017
    Posts
    5

    Getdefaultprinter problems

    GetDefaultPrinter and SetDefaulPrinter Problem

    I am having a problem with the above features in a vb6 program in Win10.

    I am writing a program in which I switch kitchen printers in a a restaurant depending on what has ben ordered (pizza at 1, burgers to another, etc.)

    When I try to switch printers using setdefaultprinter and getdefaultprinter these features do not work all the time. MS says there is a problem in previous versions such as win8 but since vb6 in win10 is not supported I am not sure what hotfix, if any, I should use.


    The following is the area of the problem. The '<<<< lines are the problem
    'This is printing for drinks
    Dim oldPrinter As String
    Printer.FontBold = True
    Printer.FontSize = 14
    If NumDrinks > 0 Then
    GoSub Headingx
    oldPrinter = GetDefaultPrinter '<<<<<<<<<<<<<<
    SetDefaultPrinter DrinkOrderPrinter <<<<<<<<<<<<<<<<<<<
    Printer.Print sServerName '( 'SERVERNUMBER)
    For XXX = 1 To NumDrinks
    Printer.Print PrintDrinkItems(XXX)
    Next XXX
    Printer.EndDoc
    End If

    'THIS IS FOR APPS ONLY PRINTING
    If NumApps > 0 And NumMains = 0 Then
    GoSub Headingx
    oldPrinter = GetDefaultPrinter '<<<<<<<<<<<<<<<<<<<<<<<
    SetDefaultPrinter FoodOrderPrinter '<<<<<<<<<<<<<<<<<<<<<<<<<
    For XXX = 1 To NumPrintedItems
    Printer.Print PrintItems(XXX)
    Next XXX
    Printer.EndDoc
    End If

  2. #2
    Join Date
    Nov 2017
    Posts
    5

    Re: Getdefaultprinter problems

    Quote Originally Posted by WWWURSA View Post
    GetDefaultPrinter and SetDefaulPrinter Problem

    I am having a problem with the above features in a vb6 program in Win10.

    I am writing a program in which I switch kitchen printers in a a restaurant depending on what has ben ordered (pizza at 1, burgers to another, etc.)

    When I try to switch printers using setdefaultprinter and getdefaultprinter these features do not work all the time. MS says there is a problem in previous versions such as win8 but since vb6 in win10 is not supported I am not sure what hotfix, if any, I should use.


    The following is the area of the problem. The '<<<< lines are the problem
    'This is printing for drinks
    Dim oldPrinter As String
    Printer.FontBold = True
    Printer.FontSize = 14
    If NumDrinks > 0 Then
    GoSub Headingx
    oldPrinter = GetDefaultPrinter '<<<<<<<<<<<<<<
    SetDefaultPrinter DrinkOrderPrinter <<<<<<<<<<<<<<<<<<<
    Printer.Print sServerName '( 'SERVERNUMBER)
    For XXX = 1 To NumDrinks
    Printer.Print PrintDrinkItems(XXX)
    Next XXX
    Printer.EndDoc
    End If

    'THIS IS FOR APPS ONLY PRINTING
    If NumApps > 0 And NumMains = 0 Then
    GoSub Headingx
    oldPrinter = GetDefaultPrinter '<<<<<<<<<<<<<<<<<<<<<<<
    SetDefaultPrinter FoodOrderPrinter '<<<<<<<<<<<<<<<<<<<<<<<<<
    For XXX = 1 To NumPrintedItems
    Printer.Print PrintItems(XXX)
    Next XXX
    Printer.EndDoc
    End If
    This is my coding for Getdefaultprinter.
    I wonder if anything is mising.

    Function SetDefaultPrinter(S As String)
    Dim WNT As Object
    Set WNT = CreateObject("WScript.Network")
    WNT.SetDefaultPrinter S
    End Function

    When I do this the string s show the right printer but prints on another.

  3. #3
    Join Date
    Nov 2017
    Posts
    5

    Re: Getdefaultprinter problems

    Westconn:
    I truly appreciate all the work you have put into this project. Your code is very elegant. I think that I may have mislead you a little bit. You mention a combobox so that the " user can select which printer to use". Let me back up a little.
    This is a Point-Of-Sale system as you see in most fast food places like McDonalds. The counter person just takes the order. the coding selects the printers. This whole printer selection process is invisible to the counter person taking the order.
    Therefore the idea of a combobox won't work.
    I think the answer is in your post. I just don't know where.

    er orders pizza and a drink. Then my coding needs to print to the pizza printer and drink printer.
    If the customer just orders pizza then the coding just need to print to the pizza printer.
    Let me go back to my original coding.


    The following is the area of the problem. This shows trying to change the printer to the drinkorderprinter (drinks)..

    Dim oldPrinter As String
    If NumDrinks > 0 Then 'The system knows if there were any drinks ordered
    oldPrinter = GetDefaultPrinter ' If there were any drinks ordered then I want to use the drinkOrderPrinter
    SetDefaultPrinter DrinkOrderPrinter 'Here I am attempting to use the DrinkOrderPrintPrinter.
    For XXX = 1 To NumDrinks
    Printer.Print PrintDrinkItems(XXX)
    Next XXX
    Printer.EndDoc
    End If

    Westconn, I am running out of time and would like to hire you to finish this. I use teamviewer. Please let me know if this is feasible.

  4. #4
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,303

    Re: Getdefaultprinter problems

    I never bother to use the get or set default printer stuff
    I just set the printer object to the printer I want to use in code.

    Typically for a two printer system I will use an ini file which contains the names of the two printers then in code activate the required printer before printing as needed.

    So in the piece of code below I have set the two variables Printer1 and Printer2 to the names of the two printers used by the app and the code sends to one or the other printer based on the stockroom var
    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
    Note that this method does not change the default printer at all. It does change the printer used by the VB program in question. There is no need to know or remember what the default printer is set to.
    Last edited by DataMiser; November 23rd, 2017 at 08:58 AM.
    Always use [code][/code] tags when posting code.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)