Autore Topic: Printer select(RISOLTO).  (Letto 1109 volte)

Offline Berserker79

  • Grande Gambero
  • ***
  • Post: 201
    • Mostra profilo
Printer select(RISOLTO).
« il: 20 Febbraio 2010, 12:46:43 »
Ciao, esiste un modo su gambas (ovviamente) che permetta di visualizzare l'elenco delle stampanti installate sul pc e di selezionare quella voluta???
Ciao e grazie anticipatamente.
« Ultima modifica: 20 Febbraio 2010, 15:18:24 da Berserker79 »

Offline fsurfing

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.484
    • Mostra profilo
Re: Printer select.
« Risposta #1 il: 20 Febbraio 2010, 13:13:30 »
puoi richiamare il dialog di stampa prima di stampare con:

Codice: [Seleziona]
IF Printer.Setup() THEN RETURN

Offline Golia

  • Senatore Gambero
  • ******
  • Post: 1.298
  • no xe mai massa tardi
    • Mostra profilo
Re: Printer select.
« Risposta #2 il: 20 Febbraio 2010, 14:00:05 »
Io ho fatto questa funzione per restare con gtk, carico il nome delle stampanti in un combobox, ecco quà
Citazione
PUBLIC SUB Form_Open()
DIM pathtofile AS String
PUBLIC idx AS Integer
pathtofile = User.Home & "/.Gestione/log_plt.txt"
SHELL ("lpstat -a | tee " & pathtofile) WAIT
idx = (Split(file.load(pathtofile), "\n").count) - 1
caricacbstampanti
END

PUBLIC SUB caricacbstampanti()
DIM hFile AS File
DIM n AS Integer
DIM i AS Integer = 0
DIM riga AS String 
DIM arr AS NEW String[idx]
  hFile = OPEN User.Home & "/.Gestione/log_plt.txt" FOR INPUT
     FOR n = 0 TO idx - 1
       LINE INPUT #hFile, riga       
       arr = Left(riga, (InStr(riga, " ") - 1))
        i = i + 1
      NEXT
    CLOSE #hFile
ComboBox1.list = arr 
END

Gradirei suggerimenti e critiche in modo da migliorare  :D

Ciao

Offline Ceskho

  • Amministratore
  • Senatore Gambero
  • *****
  • Post: 3.778
  • Vi Veri Veniversum Vivus Vici
    • Mostra profilo
    • Pagina Personale
Re: Printer select.
« Risposta #3 il: 20 Febbraio 2010, 14:54:49 »
@ golia...ma il tuo codice le mostra tutte le stampanti o ne salta una?

Offline Berserker79

  • Grande Gambero
  • ***
  • Post: 201
    • Mostra profilo
Re: Printer select.
« Risposta #4 il: 20 Febbraio 2010, 15:16:00 »
Grazie Golia, era quello che serviva a me. Infatti debbo selezionare prima la stamnpante per passarla poi ad un altro programma tramite comando shell.
comunque ho apportato delle mofiche al tuo codice:
Codice: [Seleziona]
 DIM strList, type AS String
 
 SHELL "lpstat -a | tee" TO strList
 FOR EACH type IN Split(strList, "\n")
    IF type <> "" THEN
      cmbSetSt.Add(Left(type, InStr(type, " ") - 1))
    ELSE
    END IF
 NEXT

Grazie, ciao.
« Ultima modifica: 20 Febbraio 2010, 15:17:47 da Berserker79 »

Offline Golia

  • Senatore Gambero
  • ******
  • Post: 1.298
  • no xe mai massa tardi
    • Mostra profilo
Re: Printer select(RISOLTO).
« Risposta #5 il: 20 Febbraio 2010, 17:50:54 »
@Cescho
Le legge tutte, almeno nel mio sistema

@Ber..(non potevi metterti un nik più semplice :D)
Sono contento che ti sia servito, e grazie per avere semplificato il codice,
Mi sono dimenticato di questo, cioè per leggere la stampante predefinita...se hai voglia di sistemare anche questo.. ;D
Citazione
pathtofile = User.Home & "/.Gestione/log_pltp.txt"
SHELL ("lpstat -d | tee " & pathtofile) WAIT
   hFile = OPEN pathtofile FOR INPUT
   LINE INPUT #hFile, riga
   CLOSE #hFile
   predefinita = Right(riga, (Len(riga) - InStr(riga, ": ") - 1))
Ciao grazie

Offline Berserker79

  • Grande Gambero
  • ***
  • Post: 201
    • Mostra profilo
Re: Printer select(RISOLTO).
« Risposta #6 il: 20 Febbraio 2010, 18:58:17 »
Per il momento il secondo comando che hai postato non mi serve. Lo terro a mente dovesse servirmi più avanti.
L'ho modificato così:
Codice: [Seleziona]
DIM riga AS String
SHELL "lpstat -d | tee" TO riga
textbox1.Text = Mid$(riga, InStr(riga, ":") + 2, Len(riga) - InStr(riga, ":") - 2)
Ho utilizzato la funzione Mid$ per non includere nel nome della stampante anche il carattere \n
Ciao.

Offline Golia

  • Senatore Gambero
  • ******
  • Post: 1.298
  • no xe mai massa tardi
    • Mostra profilo
Re: Printer select(RISOLTO).
« Risposta #7 il: 20 Febbraio 2010, 23:01:33 »
Ciao grazie