INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Visual Basic (Microsoft) Versions 5/6 FAQ

What VB shoud be able to do!

Printer Dialog Form -- Part 3B by CassandraR
Posted: 9 Oct 03

Continued from Part 3A -- PrintSel.frm

'---------------------------------------------------------------------------------------
' Procedure : Form_Load
' Date      : 18 May 2003
' Author    : Cassandra Roads, P. Eng.
' Copyright (c) 2003 Professional Logics Corporation
'---------------------------------------------------------------------------------------
'
Private Sub Form_Load()
    '   Clear the printer select combobox and populate it with the device names of the
    '           various printers in the Printers object.  Keep track of the default
    '           printer.
    '   Set the combobox to the default printer.
    '   Populate the other comboboxes, PaperSize and PaperBin.
    '   Get the default printer's stati and display them.
    '------------------------------------------------------------------------------------
    '
    Dim prtPrinter As Printer, intDefaultPrinter As Integer, I As Integer
    Dim strPrinterType As String, strPrinterStatus As String, strPortName As String
    Dim strComment As String, strPrinterName As String, strTemp As String
    
    cboPrinterSelect(0).Clear
    I = 0
    intDefaultPrinter = -1      ' 20031002 Correction per MZ
    For Each prtPrinter In Printers
        cboPrinterSelect(0).AddItem prtPrinter.DeviceName
        ' Following statement -- 20031002 Correction per MZ
        If prtPrinter.DeviceName = Printer.DeviceName Then _
            intDefaultPrinter = I
        I = I + I
    Next prtPrinter
    '
    Set m_prtSelectedPrinter = Printer
    '
    m_blnInProcess = True
    ' Following statement -- 20031002 Correction per MZ
    If intDefaultPrinter >= 0 Then
        cboPrinterSelect(0).ListIndex = intDefaultPrinter
    Else
        cboPrinterSelect(0).ListIndex = 0
    End If
    m_blnInProcess = False
    '
    Call PopulatePaperCBOs
    '
    If GetPrinterStati(m_prtSelectedPrinter.DeviceName, strPrinterType, _
                strPrinterStatus, strPortName, strComment) Then
        strTemp = ""
        If m_prtSelectedPrinter.DeviceName = Printer.DeviceName Then
            strTemp = "Default printer; "
        End If
        lblPrinterSelect(5).Caption = strTemp & strPrinterStatus
            
        If Len(strPrinterType) > 0 Then
            lblPrinterSelect(6).Caption = strPrinterType
        Else
            lblPrinterSelect(6).Caption = m_prtSelectedPrinter.DeviceName
        End If
            
        lblPrinterSelect(7).Caption = strPortName
        lblPrinterSelect(8).Caption = strComment
    End If
    '
End Sub
'
'----------------------------------------------------------------------------------------
'

'---------------------------------------------------------------------------------------
' Procedure : OKButton_Click
' Date      : 19 May 2003
' Author    : Cassandra Roads, P. Eng.
' Copyright (c) 2003 Professional Logics Corporation
'---------------------------------------------------------------------------------------
'
Private Sub OKButton_Click()
    Me.Hide
End Sub
'
'----------------------------------------------------------------------------------------
'

'----------------------------------------------------------------------------------------
' Procedure : PopulatePaperCBOs
' Date      : 19 May 2003
' Author    : Cassandra Roads, P. Eng.
' Copyright (c) 2003 Professional Logics Corporation
'----------------------------------------------------------------------------------------
'
Private Function PopulatePaperCBOs() As Boolean
    '   Obtain the various PaperSize and PaperBin information (both text and indices)
    '           from the printer driver.
    '   If an error occurred, then flag it and exit.
    '   Redimension the module variables to hold the non-displayed information.
    '   Copy the PaperSize text, PaperSize indices, and PaperSize dimensions to the
    '           appropriate module variables.  Keep track of the default PaperSize.
    '   Set the PaperSize combobox to display the default Papersize.
    '   Copy the PaperBin text, PaperBin indices, and PaperBin dimensions to the
    '           appropriate module variables.  Keep track of the default PaperBin.
    '   Set the PaperBin combobox to display the default PaperBin.
    '   Set the Orientation option buttons appropriate to the default settings.
    '   Flag that no errors were noted, then exit.
    '------------------------------------------------------------------------------------
    '
    Dim I As Integer, strPaperSizes() As String, intPaperSizesIndices() As Integer
    Dim apiPaperSizes() As POINTAPI, strPrinterName As String
    Dim strPaperBinNames() As String, intPaperBinNumbers() As Integer
    Dim intDefaultPaperSize As Integer, intDefaultBin As Integer, J As Integer
    
    strPrinterName = m_prtSelectedPrinter.DeviceName
    If GetPaperSizes(strPrinterName, strPaperSizes, intPaperSizesIndices, apiPaperSizes, _
                intDefaultPaperSize, strPaperBinNames, intPaperBinNumbers, _
                intDefaultBin) Then
        ' catch22 deal with the error
        PopulatePaperCBOs = True
        Exit Function
    End If
    '
    '   Copy the PaperSizes text to the combobox.
    '   Copy the PaperSizes indices to the module variable.
    '   Copy the PaperSizes sizes to the module variable.
    '
    cboPrinterSelect(1).Clear
    ReDim m_intPaperSizes(1 To UBound(strPaperSizes))
    ReDim m_apiPaperSizes(1 To UBound(strPaperSizes))
    '
    J = -1
    For I = 1 To UBound(strPaperSizes)
        cboPrinterSelect(1).AddItem strPaperSizes(I)
        m_intPaperSizes(I) = intPaperSizesIndices(I)
        m_apiPaperSizes(I) = apiPaperSizes(I)
        If m_intPaperSizes(I) = intDefaultPaperSize Then J = I
    Next I
    '
    If J > 0 Then
        cboPrinterSelect(1).ListIndex = J - 1
    Else
        cboPrinterSelect(1).ListIndex = 0
    End If
    '
    '   Copy the PaperBins text to the combobox.
    '   Copy the PaperBins indices to the module variable.
    '
    cboPrinterSelect(2).Clear
    ReDim m_intPaperBins(1 To UBound(strPaperBinNames))
    '
    J = -1
    For I = 1 To UBound(strPaperBinNames)
        cboPrinterSelect(2).AddItem strPaperBinNames(I)
        m_intPaperBins(I) = intPaperBinNumbers(I)
        If m_intPaperBins(I) = intDefaultBin Then J = I
    Next I
    '
    If J > 0 Then
        cboPrinterSelect(2).ListIndex = J - 1
    Else
        cboPrinterSelect(2).ListIndex = 0
    End If
    '
    '   Set the default paper orientation.
    '
    I = GetPrinterProperty(strPrinterName, DM_ORIENTATION)
    If I = 1 Then
        optPrinterSelect(0).Value = True
    ElseIf I = 2 Then
        optPrinterSelect(1).Value = True
    Else
        optPrinterSelect(0).Value = True
    End If
    '
    PopulatePaperCBOs = False
    '
End Function
'
'----------------------------------------------------------------------------------------
'

'---------------------------------------------------------------------------------------
' Procedure : optPrinterSelect_Click
' Date      : 18 May 2003
' Author    : Cassandra Roads, P. Eng.
' Copyright (c) 2003 Professional Logics Corporation
'---------------------------------------------------------------------------------------
'
Private Sub optPrinterSelect_Click(Index As Integer)
    
    If Index = 0 Then
        m_intPortrait = 1
    ElseIf Index = 1 Then
        m_intPortrait = 2
    End If
    
    If m_intPortrait = 1 Or m_intPortrait = 2 Then
        Call SetPrinterProperty(m_prtSelectedPrinter.DeviceName, DM_ORIENTATION, m_intPortrait)
    End If
    
End Sub
'
'----------------------------------------------------------------------------------------
'

End of PrintSel.frm

Back to Visual Basic (Microsoft) Versions 5/6 FAQ Index
Back to Visual Basic (Microsoft) Versions 5/6 Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close