Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.



Public Function varListPrinters() As Variant
' Procedure :   varListPrinters
' Description:  Generate a VARIANT ARRAY of printers.
' Copyright: Chris Greaves Inc.
' Inputs:       None
' Returns:      Array
' Assumes:      Nothing
' Side Effects:
' Tested:       By the calls listed below.
    Dim bSuccess As Boolean
    Dim iBufferRequired As Long
    Dim iBufferSize As Long
    Dim iBuffer() As Long
    Dim iEntries As Long
    Dim iIndex As Long
    Dim strPrinterName As String
    Dim iDummy As Long
'Procs    Dim iDriverBuffer() As Long
    Dim strPrinters() As String
    iBufferSize = 2000
    ReDim iBuffer((iBufferSize \ 4) - 1) As Long
    bSuccess = EnumPrinters(PRINTER_ENUM_CONNECTIONS Or PRINTER_ENUM_LOCAL, vbNullString, 1, iBuffer(0), iBufferSize, iBufferRequired, iEntries)
    If bSuccess Then
        If iBufferRequired > iBufferSize Then
            iBufferSize = iBufferRequired
            MsgBox "iBuffer too small.  Trying again with " & iBufferSize & " bytes."
            ReDim iBuffer(iBufferSize \ 4) As Long
            bSuccess = EnumPrinters(PRINTER_ENUM_CONNECTIONS Or PRINTER_ENUM_LOCAL, vbNullString, 1, iBuffer(0), iBufferSize, iBufferRequired, iEntries)
            If Not bSuccess Then
                MsgBox "Error enumerating printers."
                Exit Function
            End If
        End If
        ReDim strPrinters(iEntries - 1)
        For iIndex = 0 To iEntries - 1
            strPrinterName = Space$(StrLen(iBuffer(iIndex * 4 + 2)))
            iDummy = PtrToStr(strPrinterName, iBuffer(iIndex * 4 + 2))
            strPrinters(iIndex) = strPrinterName
        Next iIndex
    End If
    varListPrinters = strPrinters
'Sub TESTvarListPrinters()
'    Dim mes
'    mes = varListPrinters
'    Dim i As Integer
'    For i = 0 To UBound(mes)
'        MsgBox mes(i)
'    Next i
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1

Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.

Public Function varListPrinters() As Variant
' Procedure :   varListPrinters
' Description:  Generate a VARIANT ARRAY of printers.
' Copyright: Chris Greaves Inc.
' Inputs:       None
' Returns:      Array
' Assumes:      Nothing
' Side Effects:
' Tested:       By the calls listed below.
    Dim bSuccess As Boolean
    Dim iBufferRequired As Long
    Dim iBufferSize As Long
    Dim iBuffer() As Long
    Dim iEntries As Long
    Dim iIndex As Long
    Dim strPrinterName As String
    Dim iDummy As Long
'Procs    Dim iDriverBuffer() As Long
    Dim strPrinters() As String
    iBufferSize = 2000
    ReDim iBuffer((iBufferSize \ 4) - 1) As Long
    bSuccess = EnumPrinters(PRINTER_ENUM_CONNECTIONS Or PRINTER_ENUM_LOCAL, vbNullString, 1, iBuffer(0), iBufferSize, iBufferRequired, iEntries)
    If bSuccess Then
        If iBufferRequired > iBufferSize Then
            iBufferSize = iBufferRequired
            MsgBox "iBuffer too small.  Trying again with " & iBufferSize & " bytes."
            ReDim iBuffer(iBufferSize \ 4) As Long
            bSuccess = EnumPrinters(PRINTER_ENUM_CONNECTIONS Or PRINTER_ENUM_LOCAL, vbNullString, 1, iBuffer(0), iBufferSize, iBufferRequired, iEntries)
            If Not bSuccess Then
                MsgBox "Error enumerating printers."
                Exit Function
            End If
        End If
        ReDim strPrinters(iEntries - 1)
        For iIndex = 0 To iEntries - 1
            strPrinterName = Space$(StrLen(iBuffer(iIndex * 4 + 2)))
            iDummy = PtrToStr(strPrinterName, iBuffer(iIndex * 4 + 2))
            strPrinters(iIndex) = strPrinterName
        Next iIndex
    End If
    varListPrinters = strPrinters
'Sub TESTvarListPrinters()
'    Dim mes
'    mes = varListPrinters
'    Dim i As Integer
'    For i = 0 To UBound(mes)
'        MsgBox mes(i)
'    Next i
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1