Active Forums => Programs => Topic started by: Juanjogomez on January 04, 2019, 11:27:53 am
Title: Select printer
Post by: Juanjogomez on January 04, 2019, 11:27:53 am
Hi,
The program allows you to select the default printer from the list of printers that your computer has. When it starts, the red line indicates the current printer and with the arrows up and down another one is indicated in the list. With the ENTER key the new printer is selected and with the ESC key the program is left without changing it. I hope it works for you in your programs.
CLS COLOR 15, 0 SHELL _HIDE "cmd/c wmic printer get name, default> impresora.txt" DIM impresora(50) AS STRING OPEN "I", 10, "impresora.txt" n% = 0 LINE INPUT #10, dato$ DO LINE INPUT #10, dato$: LINE INPUT #10, dato$ IF EOF(10) THEN EXIT DO n% = n% + 1 DO a% = INSTR(dato$, CHR$(0)) IF a% = 0 THEN EXIT DO IF a% = 1 THEN dato$ = MID$(dato$, a% + 1) ELSEIF a% = LEN(dato$) THEN dato$ = LEFT$(dato$, a% - 1) ELSE dato$ = LEFT$(dato$, a% - 1) + MID$(dato$, a% + 1) END IF LOOP a% = INSTR(dato$, "FALSE"): b% = INSTR(dato$, "TRUE") IF a% <> 0 THEN MID$(dato$, a%, 5) = SPACE$(5) dato$ = LTRIM$(RTRIM$(dato$)) END IF IF b% <> 0 THEN MID$(dato$, b%, 5) = SPACE$(4) dato$ = LTRIM$(RTRIM$(dato$)) loca% = n% END IF impresora(n%) = dato$ impresora(0) = LTRIM$(STR$(n%)) LOOP COLOR 7, 0 CLS COLOR 1, 7 LOCATE 8, 20: PRINT "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»" LOCATE 9, 20: PRINT "º º" LOCATE 10, 20: PRINT "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹" LOCATE 11, 20: PRINT "º º" LOCATE 12, 20: PRINT "º º" LOCATE 13, 20: PRINT "º º" LOCATE 14, 20: PRINT "º º" LOCATE 15, 20: PRINT "º º" LOCATE 16, 20: PRINT "ÈÍÍÍÍÍÍÍ<Esc>ÍÍÍÍ<"; CHR$(24); ">Í<"; CHR$(25); ">ÍÍÍÍ<"; CHR$(17); CHR$(217); ">ÍÍÍÍÍÍÍÍͼ" COLOR 15, 1 LOCATE 9, 21: PRINT " SELECT PRINTER "; COLOR 1, 7 max% = VAL(impresora(0)) GOSUB impridatos DO x$ = "": WHILE x$ = "": x$ = INKEY$: WEND x$ = UCASE$(x$) x% = ASC(RIGHT$(x$, 1)) SELECT CASE x% CASE IS = 27 a$ = "@" EXIT DO CASE IS = 13 a$ = impresora(loca%) EXIT DO CASE IS = 72: '--Subir IF loca% > 1 THEN loca% = loca% - 1 GOSUB impridatos END IF CASE IS = 80: '--Bajar IF loca% < max% THEN loca% = loca% + 1 GOSUB impridatos END IF END SELECT LOOP COLOR 7, 0 CLS IF a$ <> "@" THEN SHELL _HIDE "cmd/c wmic printer where name='" + a$ + "' call setdefaultprinter" PRINT "Selected printer: "; a$ ELSE PRINT "The printer has not been modified" END IF END
impridatos: y% = 1 FOR n% = loca% - 2 TO loca% + 2 IF n% < 1 OR n% > max% THEN COLOR 1, 7: LOCATE y% + 10, 21: PRINT " " ELSE IF n% = loca% THEN COLOR 15, 4 ELSE COLOR 1, 7 LOCATE y% + 10, 21: PRINT " " LOCATE y% + 10, 21: PRINT LEFT$(impresora(n%), 40) END IF y% = y% + 1 NEXT RETURN
Title: Re: Select printer
Post by: euklides on January 05, 2019, 05:08:52 am
Another way... (using mouse)
'Printer select by Euklides, 2018 GOSUB printerSelection IF changeprint$ <> "" THEN PRINT "Active printer is now: " + changeprint$ ELSE PRINT "Printer: no change" END
'===================== printerSelection: 'use it as a sub-programme GOSUB listimp: GOSUB selspecial IF choixfait$ <> "" AND choixfait$ <> actuimp$ THEN bzz$ = choixfait$: GOSUB PRINTERMAN: changeprint$ = choixfait$ RETURN
'--- printer list--- listimp: FILETMP$ = _CWD$ + "\printy.txt": ord$ = "CMD /C" + "wmic printer get name,default > " + FILETMP$ SHELL _HIDE ord$: _DELAY .5: canal& = FREEFILE CLOSE canal&: OPEN "i", #canal&, FILETMP$: lx = LOF(canal&): np = 0: actuprint$ = "": autreprint$ = "" WHILE NOT EOF(canal&): LINE INPUT #canal&, apri1$ apri$ = "": FOR ypr = 1 TO LEN(apri1$): IF MID$(apri1$, ypr, 1) <> CHR$(0) THEN apri$ = apri$ + MID$(apri1$, ypr, 1) NEXT ypr IF INSTR(apri$ + "x", "TRUE") > 0 THEN actuprint$ = RIGHT$(apri$, LEN(apri$) - 6): impy$ = actuprint$: actuprint$ = "> " + LTRIM$(RTRIM$(actuprint$)) IF INSTR(apri$ + "x", "FALSE") > 0 THEN apri$ = RIGHT$(apri$, LEN(apri$) - 6): apri$ = LTRIM$(RTRIM$(apri$)) autreprint$ = autreprint$ + "> " + apri$ + CHR$(10) END IF WEND: CLOSE canal&: KILL FILETMP$ question$ = question$ + "Choose working printer" + CHR$(10) question$ = question$ + "*" + CHR$(10) question$ = question$ + " Actual active printer is: " + CHR$(10) + actuprint$ + CHR$(10) question$ = question$ + " Other printer available: " + CHR$(10) + autreprint$ + CHR$(10) RETURN
w = SCREEN(x, y): ima$ = ima$ + CHR$(w) w = SCREEN(x, y, 1) AND 15: ima$ = ima$ + CHR$(w) w = SCREEN(x, y, 1) \ 16: ima$ = ima$ + CHR$(w) NEXT y: NEXT x MSLV: pxq = 1: COLOR COLORAS, COLORBS: FOR x = 0 TO NELOX + 1 LOCATE MSQV + x, MSQH IF x = 0 THEN PRINT "Ú"; STRING$(LAX, "Ä"); "¿" COLOR COLORAS, COLORBS IF x > 0 AND x < NELOX + 1 THEN UQ$ = MID$(question$, pxq, LAX): PRINT "³";: IF NUMREPo = x THEN COLOR COLORBS, COLORAS IF LEFT$(UQ$, 1) <> ">" THEN COLOR 7, 0 PRINT UQ$;: COLOR COLORAS, COLORBS: PRINT "³";: pxq = pxq + LAX END IF IF x = NELOX + 1 THEN PRINT "À"; STRING$(LAX, "Ä"); "Ù"; NBEW: NEXT x MSL4: GOSUB souriskey: IF human = 1 AND z$ = CHR$(27) THEN GOTO MSL5 IF human <> 3 THEN GOTO MSL4 IF ysouris < MSQV + 1 THEN GOTO MSL4 IF ysouris > MSQV + NELOX THEN GOTO MSL4 IF xsouris < MSQH + 1 THEN GOTO MSL4 IF xsouris > MSQH + 1 + LAX THEN GOTO MSL4 numz = ysouris - MSQV: 'LOCATE 21, 1: PRINT NUM numz = (numz - 1) * LAX + 1: repW$ = RTRIM$(LTRIM$(MID$(question$, numz, LAX))) IF repW$ = "OK" THEN GOTO MSL5 IF repW$ = "CANCEL" THEN choixfait$ = "": GOTO MSL5 IF LEFT$(repW$, 1) <> ">" THEN GOTO MSL4 NUMREPo = ysouris - MSQV: choixfait$ = repW$: IF NOOK = 0 THEN GOTO MSLV ELSE GOTO MSL5 MSL5: w = 1: FOR x = 0 + MSQV TO NELOX + 1 + MSQV: FOR y = MSQH TO MSQH + LAX + 2: COLOR ASC(MID$(ima$, w + 1, 1)), ASC(MID$(ima$, w + 2, 1)) LOCATE x, y: PRINT CHR$(ASC(MID$(ima$, w, 1)));:: w = w + 3 NEXT y: NEXT x: IF LEN(choixfait$) > 0 THEN choixfait$ = RIGHT$(choixfait$, LEN(choixfait$) - 1): choixfait$ = RTRIM$(LTRIM$(choixfait$)) RETURN
RETURN '---printer activation PRINTERMAN: 'entrée avec bzz$="?" pour générer la liste des imprimantes dans sortie avec question$ 'avec bzz$="?", on a aussi le nom actuel dans Impy$ ' bzz$ avec "nom imprimante" pour la paramétrer IF bzz$ = "?" THEN GOTO listimp ord$ = "CMD /C" + "wmic printer where name='" + bzz$ + "' call setdefaultprinter" SHELL _HIDE ord$ RETURN '---mouse management souriskey: human = 0: z$ = INKEY$: IF z$ <> "" THEN human = 1: RETURN clicko = 0 IF _MOUSEINPUT THEN human = 2: xsouris = INT(_MOUSEX + .5): ysouris = INT(_MOUSEY + .5) MOUVSOURI$ = RIGHT$(STR$(ysouris + 100), 2) + "s" + RIGHT$(STR$(xsouris + 100), 2) IF _MOUSEBUTTON(1) THEN clicko = 1: human = 3 END IF RETURN '=====================
Title: Re: Select printer
Post by: SpriggsySpriggs on May 01, 2020, 08:52:32 am
Try this sometime as a means of getting printer and sending files to it for printing
copies =VAL(copies$)'Converts string value of copies$ to an integer value for counting
DOUNTIL copies =0'Performs command below until copies = 0
SHELL_HIDE_DONTWAIT"NOTEPAD /pt "+CHR$(34)+"pathtofile"+CHR$(34)+" "+CHR$(34)+ printername$ +CHR$(34)'Opens NOTEPAD and uses the /pt switch to send file to printer
copies = copies -1'Subtracts 1 from the copies integer