Change Active Printer in Alpha Four

by Ron Anusiewicz

I have always liked how Windows programs display a dialog box that allows the user to see the active printer, as well as permitting the active printer to be changed just before printing a report. So, I decided to provide the same feature in my Alpha Four application.

I modified the Mail List application that came with Alpha Four, creating four scripts to do the job. The first script is run from a button on any form which calls up a print routine. That script is PRNPHON0.SCP:

  
{IF ISBLANK(%PRNSCR), {{SET %PRNSCR, "S"}},{}}
{IF ISBLANK(%LABEL_SORT_ORDER),
 {{SET %LABEL_SORT_ORDER, "LNAME"}},{}
}
{PLAY "ACTPRNT"}
{:A}
{PLAY "PRNPHON1"}
{IF %SYS_LAST_KEY='{ESC}',{{CANCEL}},{}}
{IF %SYS_LAST_BUTTON='Cancel',{{CANCEL}},{}}
{IF %SYS_LAST_BUTTON='New Printer',
{{PLAY "CHGPRNT"}{SCREENOFF}{PLAY "ACTPRNT"}{GOTO :A}},{}
}
{CASE
%NAME_SELECTION="MARKED", {{SET %NAMES, "MARKED="Y""}},
%NAME_SELECTION="SUBLIST", {{CLEAR "%NAMES"}{PLAY "PICKSUB"}},
%NAME_SELECTION="ALL", {{CLEAR "%NAMES"}}
}
{SET %INDEX, "ML25"}
{SET %SORT, "TRIM(LNAME)+TRIM(FNAME)+TRIM(COMPANY)+TRIM(CITY)+STATE+ZIP"}
{:B}
{IF %PRNSCR="F",{{PLAY "FILENAME"}},{{GOTO :C}}}
{IF %SYS_LAST_KEY='{ESC}',{{ALTF10}{Cancel}},{}}
{SET %MESSAGE, "Saving File"}{PLAY "SHOWFILE"}
{WAITFOR 4}
{:C}
{CASE
%NAME_SELECTION="MARKED", {w1},
%NAME_SELECTION="SUBLIST", {w1{GOTO :D}},
%NAME_SELECTION="ALL", {w1{GOTO :E}}
}
prE{F2:2}{%INDEX}{F10}{DN:6}C{F5}F{F10}{%NAMES}{DN}A{F10}
{CASE
%PRNSCR="S", {S{GOTO :X}},
%PRNSCR="F", {GOTO :F}},
%PRNSCR="P", {GOTO :P}}
}
{:D}
{ALTF10}
soePEOPLIST->SUBLISTID="{%SUBLIST}"{F4}{%SORT}{F10}
{CASE
%PRNSCR="S", {prE{F10}S{GOTO :X}},
%PRNSCR="F", {prE{F10}{GOTO :F}},
%PRNSCR="P", {prE{F10}{GOTO :P}}
}
{:E}
{ALTF10}
prE{F2:2}{%INDEX}{F10}{DN:6}C{F5}F{F10:2}
{CASE
%PRNSCR="S", {S{GOTO :X}},
%PRNSCR="F", {{GOTO :F}},
%PRNSCR="P", {{GOTO :P}}
}
{:F}
{ONERROR {{GOTO :B}}}
F{%FILENAME}{F10}
{READ %OVER,24,1,10}
{IF %OVER="Overwrite ",{Y},{}}
n{F10}{CLEAR "%OVER"}
{GOTO :X}
{:P}
pnn{F10}{SCREENON}
{:X}
{TONE 350,75}{TONE 650,100}
{:Z}
When PRNPHON0.SCP runs, it sets blank variables to defaults, determines the active printer, sets a variable that has the active printer's name, and then brings up a dialog box (shown below).



If the user doesn't want to use the active printer definition, they press the New Printer button which brings them to the appropriate screen in Alpha Four. After selecting the printer definition that they want to use, the user then returns to the dialog box. From there they continue to print the report.

All of this occurs within the first 12 lines of code in the PRNPHON0.scp script. The scripts that are called are described below:

ACTPRNT
  
{SCREENOFF}
{ALTF10}
ocpC
{SET %ROW,%SYS_CURSOR_ROW}
{SET %COL,%SYS_CURSOR_COL}
{READ %ACTIVEPRINTER,%ROW,%COL,48}
{SET %ACTIVE,
"Printer: "+TRIM(SUBSTR(%ACTIVEPRINTER,4,46))}
{SET %ACTIVELENGTH,(57-LEN(%ACTIVE))/2}
{SET %SHOWPRNT,SPACE(VAL(%ACTIVELENGTH))+%ACTIVE}
{ALTF10}
The above script is run from the script "prnphon0". This script returns to the Alpha 4 main menu, then calls up "Other", "Configuration", "Printer Configuration" and "Create/Edit Printer Configuration".

Next, the variables %ROW and %COL are set.

Next, the variable %activeprinter is set starting at the row and col from the variable values of %ROW and %COL and it reads the next 48 characters in that row.

Next the variable %active is set.

The next 2 lines format the variable %showprnt so that it is displayed centered. The script then returns to the control panel.


CHGPRNT

  
{ALTF10}
{ONKEY "{ENTER}", {{ENTER}{SCREENOFF}{ENTER}}}
ocpS
{PAUSE}
{ONKEY "{ENTER}", {}}
{SCREENOFF}
This script runs if the user presses the "NEW PRINTER" button. It brings up the select printer screen.


PRNPHON0

  
{IF ISBLANK(%PRNSCR), {{SET %PRNSCR, "S"}},{}}
{IF ISBLANK(%LABEL_SORT_ORDER),
 {{SET %LABEL_SORT_ORDER, "LNAME"}},{}
}
{PLAY "ACTPRNT"}
{:A}
{PLAY "PRNPHON1"}
{IF %SYS_LAST_KEY='{ESC}',{{CANCEL}},{}}
{IF %SYS_LAST_BUTTON='Cancel',{{CANCEL}},{}}
{IF %SYS_LAST_BUTTON='New Printer',
{{PLAY "CHGPRNT"}{SCREENOFF}{PLAY "ACTPRNT"}{GOTO :A}},{}
}
{CASE
%NAME_SELECTION="MARKED", {{SET %NAMES, "MARKED="Y""}},
%NAME_SELECTION="SUBLIST", {{CLEAR "%NAMES"}{PLAY "PICKSUB"}},
%NAME_SELECTION="ALL", {{CLEAR "%NAMES"}}
}
{SET %INDEX, "ML25"}
{SET %SORT, "TRIM(LNAME)+TRIM(FNAME)+TRIM(COMPANY)+TRIM(CITY)+STATE+ZIP"}
{:B}
{IF %PRNSCR="F",{{PLAY "FILENAME"}},{{GOTO :C}}}
{IF %SYS_LAST_KEY='{ESC}',{{ALTF10}{Cancel}},{}}
{SET %MESSAGE, "Saving File"}{PLAY "SHOWFILE"}
{WAITFOR 4}
{:C}
{CASE
%NAME_SELECTION="MARKED", {w1},
%NAME_SELECTION="SUBLIST", {w1{GOTO :D}},
%NAME_SELECTION="ALL", {w1{GOTO :E}}
}
prE{F2:2}{%INDEX}{F10}{DN:6}C{F5}F{F10}{%NAMES}{DN}A{F10}
{CASE
%PRNSCR="S", {S{GOTO :X}},
%PRNSCR="F", {GOTO :F}},
%PRNSCR="P", {GOTO :P}}
}
{:D}
{ALTF10}
soePEOPLIST->SUBLISTID="{%SUBLIST}"{F4}{%SORT}{F10}
{CASE
%PRNSCR="S", {prE{F10}S{GOTO :X}},
%PRNSCR="F", {prE{F10}{GOTO :F}},
%PRNSCR="P", {prE{F10}{GOTO :P}}
}
{:E}
{ALTF10}
prE{F2:2}{%INDEX}{F10}{DN:6}C{F5}F{F10:2}
{CASE
%PRNSCR="S", {S{GOTO :X}},
%PRNSCR="F", {{GOTO :F}},
%PRNSCR="P", {{GOTO :P}}
}
{:F}
{ONERROR {{GOTO :B}}}
F{%FILENAME}{F10}
{READ %OVER,24,1,10}
{IF %OVER="Overwrite ",{Y},{}}
n{F10}{CLEAR "%OVER"}
{GOTO :X}
{:P}
pnn{F10}{SCREENON}
{:X}
{TONE 350,75}{TONE 650,100}
{:Z}


The first 12 lines of this script do all the work relating to the select printer option. All the rest is my code to run the reports. After line 12, you insert your own code.

The first 3 lines just set variables if they are blank.

The next line get the active printer to be displayed.

The next Play displays the dialog box. The rest of the script handles key inputs or button pushes.


PRNPHON1


Name        : PRNPHON1    
Description : Print Mailing Labels, New    
Row         : 4
Col         : 10
Height      : 11
Width       : 61
 
 
 
Variable     : %SHOWPRNT
Control Type : Display
Row          : 7
Column       : 5
Width        : 53
 
Text         : New Printer    
Control Type : Button
Script       : None
Help Text    : None
Row          : 9
Column       : 11
 
Text         : Ok    
Control Type : Button
Script       : None
Help Text    : None
Row          : 9
Column       : 35
 
Text         : Cancel    
Control Type : Button
Script       : None
Help Text    : None
Row          : 9
Column       : 45
This is the dialog script.