Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21690

Paper Bin Codes

$
0
0
I want to find the paper bin code numbers for my
Cannon MG6250 I found this code on a Microsoft
web page can it be run this from VB6? if yes could you
please show me what I need to amend.
like what is Application,strName
Code:

VBA
Module

Option Explicit

' Declaration for the DeviceCapabilities function API call.
Private Declare Function DeviceCapabilities Lib "winspool.drv" _
    Alias "DeviceCapabilitiesA" (ByVal lpsDeviceName As String, _
    ByVal lpPort As String, ByVal iIndex As Long, lpOutput As Any, _
    ByVal lpDevMode As Long) As Long
   
' DeviceCapabilities function constants.
Private Const DC_PAPERNAMES = 16
Private Const DC_PAPERS = 2
Private Const DC_BINNAMES = 12
Private Const DC_BINS = 6
Private Const DEFAULT_VALUES = 0

Form
Sub GetBinList(strName As String)
' Uses the DeviceCapabilities API function to display a
' message box with the name of the default printer and a
' list of the paper bins it supports.
 
    Dim lngBinCount As Long
    Dim lngCounter As Long
    Dim hPrinter As Long
    Dim strDeviceName As String
    Dim strDevicePort As String
    Dim strBinNamesList As String
    Dim strBinName As String
    Dim intLength As Integer
    Dim strMsg As String
    Dim aintNumBin() As Integer
   
    On Error GoTo GetBinList_Err
   
    ' Get name and port of the default printer.
    strDeviceName = Application.Printers(strName).DeviceName
    strDevicePort = Application.Printers(strName).Port
   
    ' Get count of paper bin names supported by the printer.
    lngBinCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, _
        lpPort:=strDevicePort, _
        iIndex:=DC_BINNAMES, _
        lpOutput:=ByVal vbNullString, _
        lpDevMode:=DEFAULT_VALUES)
   
    ' Re-dimension the array to count of paper bins.
    ReDim aintNumBin(1 To lngBinCount)
   
    ' Pad variable to accept 24 bytes for each bin name.
    strBinNamesList = String(Number:=24 * lngBinCount, Character:=0)
 
    ' Get string buffer of paper bin names supported by the printer.
    lngBinCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, _
        lpPort:=strDevicePort, _
        iIndex:=DC_BINNAMES, _
        lpOutput:=ByVal strBinNamesList, _
        lpDevMode:=DEFAULT_VALUES)
       
    ' Get array of paper bin numbers supported by the printer.
    lngBinCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, _
        lpPort:=strDevicePort, _
        iIndex:=DC_BINS, _
        lpOutput:=aintNumBin(1), _
        lpDevMode:=0)
       
    ' List available paper bin names.
    strMsg = "Paper bins available for " & strDeviceName & vbCrLf
    For lngCounter = 1 To lngBinCount
       
        ' Parse a paper bin name from string buffer.
        strBinName = Mid(String:=strBinNamesList, _
            Start:=24 * (lngCounter - 1) + 1, _
            Length:=24)
        intLength = VBA.InStr(Start:=1, _
            String1:=strBinName, String2:=Chr(0)) - 1
        strBinName = Left(String:=strBinName, _
                Length:=intLength)
 
        ' Add bin name and number to text string for message box.
        strMsg = strMsg & vbCrLf & aintNumBin(lngCounter) _
            & vbTab & strBinName
           
    Next lngCounter
       
    ' Show paper bin numbers and names in message box.
    MsgBox Prompt:=strMsg
   
GetBinList_End:
    Exit Sub
GetBinList_Err:
    MsgBox Prompt:=Err.Description, Buttons:=vbCritical & vbOKOnly, _
        Title:="Error Number " & Err.Number & " Occurred"
    Resume GetBinList_End
End Sub


Viewing all articles
Browse latest Browse all 21690

Trending Articles