Springen naar inhoud

- - - - -

Default Printer Terug Te Zetten Na Afdrukken Pdf

  • Log in a.u.b. om te beantwoorden
Er zijn 2 reacties in dit onderwerp

#1 houthalen


    Senior Developer

  • Leden
  • PipPipPip
  • 172 berichten
    Laatst bezocht gisteren, 07:34

Geplaatst op 04 december 2016 - 20:45

Private Sub Command1_Click()
Label1.Caption = Printer.DeviceName ' bewaar actueel default printer
Unload Form1
Printer.DeviceName = Label1.Caption ' terugzetten default printer
End Sub

Ik probeer het volgende:
Met deze code selecteer ik met commondialog het PDF printer
Dan wordt form1 gesaved als pdf
Ik probeer dan de default printer terug te zetten.

Maar ik krijg error  Wrong Number of Arguments or invalid Property assignement hier
Printer.DeviceName = Label1.Caption

Hoe moet ik het verbeteren om de default printer terug te zetten?
dank u

#2 Hansiebebe


    Professional Developer

  • Leden
  • PipPipPipPip
  • 335 berichten
    Laatst bezocht 07 apr 2020 15:37

Geplaatst op 22 december 2016 - 23:09

bevind de label zich ook op Form1 ?
want dan zou ik de Unload pas doen als je default printer hebt terug gezet

#3 RedThread


    Beheerder VBIB

  • Beheerder
  • 3600 berichten
    Laatst bezocht 08 jul 2020 14:53
  • LocatieTongeren,Belgium.

Geplaatst op 23 december 2016 - 09:59

Dag Houthalen,

Kijkt eens of je met onderstaande code verder kan.

copyrights : http://vbnet.mvps.or...aultprinter.htm

Option Explicit
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
' Distribution: You can freely use this code in your own
'			   applications, but you may not reproduce 
'			   or publish this code on any web site,
'			   online service, or distribute as source 
'			   on any media without express permission.
Private Const HWND_BROADCAST As Long = &HFFFF&
Private Const WM_WININICHANGE As Long = &H1A

Private Declare Function GetProfileString Lib "kernel32" _
   Alias "GetProfileStringA" _
  (ByVal lpAppName As String, _
   ByVal lpKeyName As String, _
   ByVal lpDefault As String, _
   ByVal lpReturnedString As String, _
   ByVal nSize As Long) As Long

Private Declare Function WriteProfileString Lib "kernel32" _
   Alias "WriteProfileStringA" _
  (ByVal lpszSection As String, _
   ByVal lpszKeyName As String, _
   ByVal lpszString As String) As Long

Private Declare Function SendNotifyMessage Lib "user32" _
   Alias "SendNotifyMessageA" _
  (ByVal hwnd As Long, _
   ByVal msg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long   

Private Sub Form_Load()

	ProfileLoadWinIniList List1, "PrinterPorts"
	Command1.Enabled = False

End Sub

Private Sub Command1_Click()

   Call SetDefaultPrinterWinNT

End Sub

Private Sub List1_Click()

   Command1.Enabled = List1.ListIndex > -1

End Sub

Private Sub SetDefPrinter(ByVal PrinterName As String, _
						  ByVal DriverName As String, _
						  ByVal PrinterPort As String)
   Dim DeviceLine As String

  'rebuild a valid device line string
   DeviceLine = PrinterName & "," & DriverName & "," & PrinterPort

  'Store the new printer information in the
  '[WINDOWS] section of the WIN.INI file for
  'the DEVICE= item
   Call WriteProfileString("windows", "Device", DeviceLine)

  'Cause all applications to reload the INI file
   Call SendNotifyMessage(HWND_BROADCAST, WM_WININICHANGE, 0, ByVal "windows")

End Sub

Private Sub GetDriverAndPort(ByVal Buffer As String, _
							 DriverName As String, _
							 PrinterPort As String)

   Dim posDriver As Long
   Dim posPort As Long
   DriverName = ""
   PrinterPort = ""

  'The driver name is first in the string
  'terminated by a comma
   posDriver = InStr(Buffer, ",")

   If posDriver > 0 Then

	 'Strip out the driver name
	  DriverName = Left(Buffer, posDriver - 1)

	 'The port name is the second entry after
	 'the driver name separated by commas.
	  posPort = InStr(posDriver + 1, Buffer, ",")

	  If posPort > 0 Then

		'Strip out the port name
		 PrinterPort = Mid(Buffer, posDriver + 1, posPort - posDriver - 1)

	   End If
   End If

End Sub

Private Function ProfileLoadWinIniList(lst As ListBox, _
									   lpSectionName As String) As Long

'Load the listbox data from win.ini.

   Dim success As Long
   Dim nSize As Long
   Dim lpKeyName As String
   Dim ret As String

  'call the API passing null as the parameter
  'for the lpKeyName parameter. This causes
  'the API to return a list of all keys under
  'that section. Pad the passed string large
  'enough to hold the data. Adjust to suit.
   ret = Space$(8102)
   nSize = Len(ret)
   success = GetProfileString(lpSectionName, _
							  vbNullString, _
							  "", _
							  ret, _

  'The returned string is a null-separated
  'list terminated by a pair of null characters.
   If success Then

	 'trim terminating null and trailing spaces
	  ret = Left$(ret, success)

		'with the resulting string,
		'extract each element
		 Do Until ret = ""

		   'strip off an item and
		   'add the item to the listbox
			lpKeyName = StripNulls(ret)
			lst.AddItem lpKeyName


   End If

  'return the number of items as an
  'indicator of success
   ProfileLoadWinIniList = lst.ListCount

End Function

Private Function StripNulls(startstr As String) As String

 'Take a string separated by chr$(0)
 'and split off 1 item, shortening the
 'string so next item is ready for removal.
  Dim pos As Long

  pos = InStr(startstr$, Chr$(0))

  If pos Then

	  StripNulls = Mid$(startstr, 1, pos - 1)
	  startstr = Mid$(startstr, pos + 1, Len(startstr))

  End If

End Function

Private Sub SetDefaultPrinterWinNT()

   Dim Buffer As String
   Dim DeviceName As String
   Dim DriverName As String
   Dim PrinterPort As String
   Dim PrinterName As String
   Dim r As Long

   If List1.ListIndex > -1 Then

	 'Get the printer information for the currently selected
	 'printer in the list. The information is taken from the
	 'WIN.INI file.
	  Buffer = Space(1024)
	  PrinterName = List1.list(list1.ListIndex)

	  Call GetProfileString("PrinterPorts", _
							 PrinterName, "", _
							 Buffer, Len(Buffer))

	 'Parse the driver name and port name out of the buffer
	  GetDriverAndPort Buffer, DriverName, PrinterPort

	  If (Len(DriverName) > 0) And (Len(PrinterPort) > 0) Then
		 SetDefPrinter PrinterName, DriverName, PrinterPort
	  End If

	End If

End Sub

Ook met taq VB6 voorzien

0 gebruiker(s) lezen dit onderwerp

0 lid(leden), 0 bezoeker(s), 0 anonieme gebruikers


[VB6] Untitled 1

Met dank aan Jürgen voor de jarenlange inzet van visualbasic.be (anno dec 2000)
Met dank aan Mike en Ronneke voor de jarenlange inzet van vbib.be (anno dec 2010)
Met dank aan PascalBianca voor de jarenlange inzet van vbib.be (anno dec 2016)