hi guys! I'm not quite sure if this qualifies as a QUICK question but I'm gonna ask anyway!
Ok i'd like to populate a combobox with a list of available printers.
I'm aware lpstat -a in a konsole yields the result I'm after but I can't figure out how to apply that to Gambas!
Anyone able to help me out........ again!
Load available printers to a combobox
Re: Load available printers to a combobox
If you want to know a list of available printers in your system, maybe this page can help you:
https://www.gambas-it.org/wiki/index.ph ... io_sistema
https://www.gambas-it.org/wiki/index.ph ... io_sistema
Europaeus sum !
Amare memorentes atque deflentes ad mortem silenter labimur.
Amare memorentes atque deflentes ad mortem silenter labimur.
Re: Load available printers to a combobox
Try this routine (Note: I did write it here without testing and the IDE for syntax control):
The Print instruction can be replaced by placing it in for example a ListView.
You can further refine the output by searching each sLine for the position of the text 'accepting' and use some String functions to cut of the line and have just printer name remaining. Look for functions like Instr() to determine position and Left() etc. to remove the unwanted text.
Enjoy
Public Sub ListPrinters()
Dim aPrinters As String[]
Dim sOut, sLine As String
Exec["lpstat", "-a"] Wait To sOut
aPrinters = Split(sOut, "\n")
For Each sLine in aPrinters
Print sLine
Next
End
The Print instruction can be replaced by placing it in for example a ListView.
You can further refine the output by searching each sLine for the position of the text 'accepting' and use some String functions to cut of the line and have just printer name remaining. Look for functions like Instr() to determine position and Left() etc. to remove the unwanted text.
Enjoy
gbWilly
- Dutch translation for Gambas3
- Gambas wiki content contributer
- Gambas3 Debian repository
... there is always a Catch if things go wrong!
- Dutch translation for Gambas3
- Gambas wiki content contributer
- Gambas3 Debian repository
... there is always a Catch if things go wrong!
- cogier
- Site Admin
- Posts: 1158
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Load available printers to a combobox
Well, here is my solution. The code requires that ComboBox1 to be on the Form.
Public Sub ListPrinters()
Dim sPrinters As String[] 'To store the printers
Dim sList, sDefault As String 'sList will store all the Printers, sDefault will store the Default Printer
Dim iLoop As Integer 'Loop counter
Shell "lpq" To sDefault 'Get the Default Printer
sDefault = Left(sDefault, InStr(sDefault, " ") - 1) 'Shorten the returned description
Shell "lpstat -a" To sList 'Get a list of all the Printers
sPrinters = Split(sList, gb.NewLine, "", True) 'Split the list and store in sPrinters
For iLoop = 0 To sPrinters.Max 'Loop through all the Printers
sPrinters[iloop] = Left(sPrinters[iloop], InStr(sPrinters[iloop], " ") - 1) 'Shorten the returned description
Next
ComboBox1.List = sPrinters 'Add the Printers to the ComboBox
ComboBox1.Text = sDefault 'Display the Default Printer
End
- BruceSteers
- Posts: 1838
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Load available printers to a combobox
If you are planning on using gb.form.print you can maybe use the Printer.List property?
ComboBox1.List = Printer.List
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: Load available printers to a combobox
Thanks for all the replies . Cogler your's worked perfectly. This is why i love linux, the community support is amazing!