Coronavirus (Covid-19): Latest updates and information
Skip to main content Skip to navigation

Example of bad virtual agency code

Warning: this example is not recommended (see section 6 of The Not-So-Quick Guide to dtkeden)

The following two code segments show how to use virtual agency to create 150 buttons on a screen.  The first segment defines a panel for a primitive button whose name is specified by the variable buttonID. The variables buttonNo, buttonWidth, buttonLength, buttonScreen, buttonScreenPosX, buttonScreenPosY and maxColumns are defined in the second segment.

The first segment:

display buttonWin;
window button;
integer buttonPosX, buttonPosY;
string buttonLabel;
button = {
   frame : ([{buttonPosX, buttonPosY}, {buttonPosX + (~buttonWidth), buttonPosY + (~buttonLength)}]),
   string : buttonLabel,
   relief : "raised",
   border : 2,
   bgcolor : "blue",
   fgcolor : "white",
   alignment : CENTRE,
   sensitive : ON
buttonWin = <button>;
~buttonsScreen &= buttonWin;
buttonLabel = ~buttonID;
buttonPosX = ~buttonsScreenPosX + (~buttonNo % ~maxColumns) * (~buttonWidth);
buttonPosY = ~buttonsScreenPosY + (~buttonNo/~maxColumns) * (~buttonLength);


The second segment shows how to use the command include to instantiate a button from the button panel in the first segment.

The second segment:

display buttonsScreen;
integer buttonsScreenPosX, buttonsScreenPosY;
integer buttonLength, buttonWidth;
screen = buttonsScreen;

proc init {
  auto i, j;
for (i=0; i<maxRows; i++) {
    for (j=0; j<maxColumns; j++) {
        buttonID = "w" // str(i) // "w"// str(j); /* specify button name */
        buttonNo = i * maxColumns + j;
        include("button.panel"); /* instantiate a button */
maxColumns = 15;
maxRows = 10;
buttonsScreenPosX = 100;
buttonsScreenPosY = 100;
buttonLength = 30;
buttonWidth = 30;


To run these two code segments as a program to generate a bank of buttons, the first segment needs to be stored in a file called "button.panel" in the directory where dtkeden was started from.  It is then necessary to include the second segment into the input window of dtkeden and click the "Accept" menu item.