Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > API and Miscellaneous Code Examples

How to get information on the printer type, driver and port.

How to get information on the printer type, driver and port. 'Note: This has only been tested with VB 3 & VB 4-16, if you convert 'Declare this API: Declare Function GetPrivateProfileString% Lib "Kernel" (ByVal lpAppName$, ByVal lpKeyName As Any, ByVal lpDefault$, ByVal lpReturnedString$, ByVal nSize%, ByVal lpFileName$) 'Add this code to the appropriate routine: 'String variables to store section and key AppName$ = "windows" KeyName$ = "device" ' Return string length nSize% = 81 RetStr$ = Space$(nSize%) NumChars% = GetProfileString(AppName$, KeyName$, NullStr$, RetStr$, nSize%) ' Store the string koRetStr$ = Left$(RetStr$, NumChars%) ' Parse the string for specifics ' Find the first comma CommaPos1% = InStr(1, RetStr$, ",") ' Find the next comma CommaPos2% = InStr(CommaPos1% + 1, RetStr$, ",") ' Get Windows printer type lblPrinter.Caption = Left$(RetStr$, CommaPos1% - 1) 'Get the Printer driver lblPrinterDriver.Caption = Mid$(RetStr$, CommaPos1% + 1, CommaPos2% - CommaPos1% - 1) & ".DRV" 'Get the Printer port lblPrinterPort.Caption = Mid$(RetStr$, CommaPos2% + 1)