ETHZ_Logo RAMSES_Logo_Right    RAMSES    RAMSES_Logo_Left Systems Ecology   

Dialog Machine Snippets

1 - Introduction

The following code snippets demonstrate the typical usage of the Dialog Machine. Under a given header they provide copy and paste snippets for the necessary imports, constant or variable declarations plus the typical statements required to implement the desired function.

Dialog Machine Version 3.0
Copyright (c) 1988-2006 by Andreas Fischlin and ETH Zurich
https://www.sysecol.ethz.ch

2 - Files


  (*----------------------------------------------------*)
  (*=====   Open an existing file without dialog   =====*)
  (*----------------------------------------------------*)
  

 
  FROM DMLanguage IMPORT fileResBase;
  FROM DMMessages IMPORT DoInform; 
 
  FROM DMFiles IMPORT TextFile, neverOpenedFile, 
    Lookup, Response, Close;
    
  VAR
    myFile: TextFile;
    
    myFile.filename := "The File";
    Lookup(myFile,myFile.filename,FALSE(*new*));
    IF (myFile.res=done) THEN
      (*. *** read from it as you want *** .*)
    ELSE (* an error occurred *)
      DoInform(fileResBase+ORD(myFile.res),
               "MyModule","MyProcedure",myFile.filename);
    END(*IF*);
   
   
    myFile := neverOpenedFile;


    
    
    (*----------------------------------------------------------------------*)
    (*=====   Open a new (or overwrite existing) file without dialog   =====*)
    (*----------------------------------------------------------------------*)
    
    
 
  FROM DMLanguage IMPORT fileResBase;
  FROM DMMessages IMPORT DoInform; 
 
  FROM DMFiles IMPORT TextFile, neverOpenedFile, 
    Lookup, Response, Close;
    
  VAR
    myFile: TextFile;
    
    myFile.filename := "The File";
    Lookup(myFile,myFile.filename,TRUE(*new*));
    IF (myFile.res=done) THEN
      (*. *** write on it as you want *** .*)
    ELSE (* an error occurred *)
      DoInform(fileResBase+ORD(myFile.res),
               "MyModule","MyProcedure",myFile.filename);
    END(*IF*);
   
   
    myFile := neverOpenedFile;


  
    
    
    (*---------------------------------------------------*)
    (*=====   Open a file with dialog for reading   =====*)
    (*---------------------------------------------------*)
    
  
    
 
  FROM DMLanguage IMPORT allOk, fileResBase;
  FROM DMMessages IMPORT DoInform; 
 
  FROM DMFiles IMPORT TextFile, neverOpenedFile, 
    GetExistingFile, Response, Close;
    
  VAR
    myFile: TextFile; resCode: INTEGER;
    
    GetExistingFile(myFile,"Please select file 'The File'");
    IF (myFile.res=done) THEN
      (*. *** read from it as you want *** .*)
    ELSIF (myFile.res<>cancelled) THEN (* an error occurred *)
      resCode := fileResBase+ORD(myFile.res);
      DoInform(resCode,"MyModule","MyProcedure",myFile.filename);
    ELSE
      (*. restore or do nothing, since cancelled .*)
    END(*IF*);
   
   
    myFile := neverOpenedFile;
   
   
    
    (*---------------------------------------------------*)
    (*=====   Open a file with dialog for writing   =====*)
    (*---------------------------------------------------*)
    
 
  FROM DMLanguage IMPORT allOk, fileResBase;
  FROM DMMessages IMPORT DoInform; 
  FROM DMStrings  IMPORT AssignString;
 
  FROM DMFiles IMPORT TextFile, neverOpenedFile, 
    CreateNewFile, Response, Close;
    
  VAR
    myFile: TextFile; resCode: INTEGER;
    
   
    CreateNewFile(myFile,"Save as",myFile.filename);
    IF (myFile.res=done) THEN
      (*. *** write to it as you want *** .*)
    ELSIF (myFile.res<>cancelled) THEN (* an error occurred *)
      resCode := fileResBase+ORD(myFile.res);
      DoInform(resCode,"MyModule","MyProcedure",myFile.filename);
    ELSE
      (*. restore or do nothing, since cancelled .*)
    END(*IF*);
   
   
    myFile := neverOpenedFile;
    AssignString("DefaultName",myFile.filename);

3 - File I/O


  (*-----------------------------------*)
  (*=====   Reading from a file   =====*)
  (*-----------------------------------*)

  FROM DMFiles IMPORT TextFile, neverOpenedFile, 
    Lookup, GetExistingFile, Response, Close, 
    IsOpen, EOF, EOL, ReadChar;
    
    

  (* the following snippet assumes the file is already open *)
  
  PROCEDURE ReadLn (VAR f: TextFile; VAR line: ARRAY OF CHAR);
    VAR i,n: INTEGER; ch: CHAR;
  BEGIN (* ReadLn *)
    line[0] := 0C; 
    IF NOT IsOpen(f) OR EOF(f) THEN RETURN END;
    n := HIGH(line); i := 0; ReadChar(f,ch);
    WHILE (i<=n) AND (ch<>EOL) AND NOT EOF(f) DO
      line[i] := ch;
      ReadChar(f,ch); INC(i);
    END(*WHILE*);
    IF i<=n THEN line[i] := 0C END;
  END ReadLn;

4 - Windows


  (*-------------------------------*)
  (*=====   Create a window   =====*)
  (*-------------------------------*)

  
  FROM DMWindows IMPORT Window, WindowsDone, notExistingWindow,
    WindowKind, ScrollBars, CloseAttr, ZoomAttr, WFFixPoint, 
    WindowFrame, CreateWindow, AutoRestoreProc;
  FROM DMWindIO IMPORT BackgroundWidth, BackgroundHeight;

  VAR
    myWindow: Window;
    
  PROCEDURE MakeMyWindow;
    VAR wf: WindowFrame;
  BEGIN 
    wf.x := margin;
    wf.y := margin;
    wf.w := BackgroundWidth()-2*margin;
    wf.h := BackgroundHeight()-2*margin;
    CreateWindow(myWindow,
                 GrowOrShrinkOrDrag, WithoutScrollBars,
                 WithCloseBox, WithZoomBox, bottomLeft,
                 wf, "MyWindow", AutoRestoreProc);
    IF WindowsDone THEN
      (*.  AddWindowHandler(.., SetWindowFont(...  or any other
      action depending on the existence of the window myWindow .*)
    END(*IF*);
  END MakeMyWindow;
  
    
    myWindow := notExistingWindow;
    MakeMyWindow;

5 - Entry Forms (elementary data types)


  (*---------------------------------------*)
  (*=====   Entry forms  -  INTEGER   =====*)
  (*---------------------------------------*)


  FROM DMEntryForms IMPORT FormFrame, WriteLabel, DefltUse, UseEntryForm, 
    IntField, LongRealField, CheckBox, StringField, CharField;
    
  VAR
    theInt: INTEGER;
   
  PROCEDURE DoEntryForm;
    CONST lem = 5; tab = 30; 
    VAR ef: FormFrame; ok: BOOLEAN; cl: INTEGER;
  BEGIN (*DoEntryForm*)
    cl := 2;
    WriteLabel(cl,lem,"Title"); INC(cl);
    WriteLabel(cl,lem,"DescriptionOfInteger");
    IntField(cl,tab,7,theInt,useAsDeflt,MIN(INTEGER),MAX(INTEGER)); INC(cl);
    ef.x:= 0; ef.y:= -1 (*display entry form in middle of screen*);
    ef.lines:= cl+1; ef.columns:= 55;
    UseEntryForm(ef,ok);
  END DoEntryForm;

  
  
  (*------------------------------------*)
  (*=====   Entry forms  -  REAL   =====*)
  (*------------------------------------*)
  
    
  VAR
    theReal: LONGREAL;
   
  (*. insert in DoEntryForm (see above) following editable field .*)
  
    WriteLabel(cl,lem,"DescriptionOfReal");
    LongRealField(cl,tab,7,theReal,useAsDeflt,minTheReal,maxTheReal); INC(cl);
      

    
    (*--------------------------------------------------*)
    (*=====   Entry forms  -  CheckBox (BOOLEAN)   =====*)
    (*--------------------------------------------------*)
    
    
  VAR
    theOptionFlag: BOOLEAN;
   
  (*. insert in DoEntryForm (see above) following editable field .*)
  
    CheckBox(cl,lem,"DescriptionOfOption",theOptionFlag); INC(cl);
      

    
    (*--------------------------------------*)
    (*=====   Entry forms  -  String   =====*)
    (*--------------------------------------*)
    
    

  VAR
    theString: ARRAY [0..hi] OF CHAR;
  
  CONST
    fieldwidth = 20;
    
  (*. insert in DoEntryForm (see above) following editable field .*)
  
    StringField(cl,tab,fieldwidth,theString,useAsDeflt); INC(cl);
      

    
    (*------------------------------------*)
    (*=====   Entry forms  -  CHAR   =====*)
    (*------------------------------------*)
    
    
  VAR
    theChar: CHAR;
    
  (*. add in DoEntryForm (see above) following constant(s) .*)    
    
      anyCharLegal   = 177C;   (* any char is legal, even none *)
      just1CharLegal = "";     (* any char is legal, but one must be entered *) 
      
  (*. insert in DoEntryForm (see above) following editable field .*)
  
    WriteLabel(cl,lem,"Character");
    CharField(cl,tab,theChar,useAsDeflt,legalCharset); INC(cl);   
      
    
  
    (*---------------------------------------------*)
    (*=====   Entry forms  -  Radio Buttons   =====*)
    (*---------------------------------------------*)
    

  FROM DMEntryForms IMPORT RadioButtonID, DefineRadioButtonSet,
    RadioButton, FormFrame, WriteLabel, DefltUse, UseEntryForm;

  TYPE
    ColorChoices = (brownish, greenish); (* extend at your heart's content *)

  VAR
    curCol: ColorChoices;
   
    
    
  TYPE
    Choices = ColorChoices; (*. equivalent local type with yours .*)
    
  PROCEDURE DoEntryForm(VAR curChoice(*In/Out*): Choices);
    CONST lem = 5; tab = 30; 
    VAR ef: FormFrame; ok: BOOLEAN; cl: INTEGER; 
      makeChoiceRadButSet: RadioButtonID; 
      radBut: ARRAY [MIN(Choices)..MAX(Choices)] OF RadioButtonID;
      radButTxt: ARRAY [MIN(Choices)..MAX(Choices)] OF ARRAY [0..31] OF CHAR;
    PROCEDURE MakeRadButtonSet(curChoice: Choices);
      VAR ci: Choices;
    BEGIN (* MakeRadButtonSet *)
      DefineRadioButtonSet(makeChoiceRadButSet);
      FOR ci := MIN(Choices) TO MAX(Choices) DO
        RadioButton( radBut[ci], cl, lem, radButTxt[ci]); INC(cl);
      END(*FOR*);
      makeChoiceRadButSet := radBut[curChoice];
    END MakeRadButtonSet;
    PROCEDURE WhichChoice(chosenRBut: RadioButtonID; 
                          rb: ARRAY OF RadioButtonID): Choices;
      VAR i: Choices;
    BEGIN (* WhichChoice *)
      i := MIN(Choices);
      WHILE (irb[ORD(i)]) DO 
        INC(i) 
      END(*WHILE*);
      RETURN i
    END WhichChoice;
  BEGIN (*DoEntryForm*)
    cl := 2;
    WriteLabel(cl,lem,"Choose a color"); INC(cl);
    (*. Assign here labels (text) of radio buttons .*)
    radButTxt[brownish] := "Brownish color";
    radButTxt[greenish] := "Greenish color";
    MakeRadButtonSet(curChoice);
    ef.x:= 0; ef.y:= -1 (*display entry form in middle of screen*);
    ef.lines:= cl+1; ef.columns:= 55;
    UseEntryForm(ef,ok);
    IF ok THEN
      curChoice := WhichChoice(makeChoiceRadButSet, radBut);
    END; (* IF *)
  END DoEntryForm;

    
  (*----------------------------*)
  (*=====   Ask question   =====*)
  (*----------------------------*)
    
  
  FROM DMMessages IMPORT Ask;    
   
   
  PROCEDURE YouWantToContinue(): BOOLEAN;
    CONST yes=1; no=2; VAR answer: INTEGER;
  BEGIN
    Ask("Do you wish to continue?","Yes|No",7,answer); (* default yes *)
    RETURN answer=yes;
  END YouWantToContinue;

6 - Dynamic Entry Forms


  FROM DMLanguage IMPORT 
    okButtonText, cancelButtonText;                                
  FROM DMWindows IMPORT 
    Window, WindowFrame, 
    ModalWindowKind, ScrollBars, 
    CreateModalWindow, UseWindowModally,
    AutoRestoreProc, RemoveWindow;
  FROM DMWindIO IMPORT 
    SelectForOutput, 
    SetWindowFont, WindowFont, FontStyle, CellWidth, 
    BackgroundWidth, BackgroundHeight,
    SetPen, WriteString;
  FROM DMEditFields IMPORT 
    EditItem,
    MakeIntField, IsInteger,
    MakePushButton, UseAsDefaultButton,
    SelectField;
    
  
  
  VAR
    theInt1: INTEGER;
    theInt2: INTEGER;
    
  TYPE 
    MyModalDialog = RECORD
      myEntryForm: Window;  
      wf: WindowFrame; 
      acceptIt, cancelled, entryFormOk: BOOLEAN;
      okBut, cancelBut: EditItem;
      (*. from here on insert your dialog specific objects .*)
      middle, yTxtLn: INTEGER;
      oldInt1: INTEGER; intF1: EditItem;
      oldInt2: INTEGER; intF2: EditItem; 
      myBut: EditItem;
      (*. define more of your own objects ad libitum .*)
      (*. ... .*)
    END (* RECORD *);

  VAR
    mdlg: MyModalDialog;
    

      
  PROCEDURE DoOk;
  BEGIN
    (* get possibly edited, new values *)
    mdlg.acceptIt := IsInteger(mdlg.intF1, theInt1) AND
                IsInteger(mdlg.intF2, theInt2);
    (*. possibly make further tests, e.g. conistency tests,
        before accepting the values definitely .*)                
  END DoOk;
  
  PROCEDURE DoCancel;
  BEGIN
    mdlg.cancelled:=TRUE;  
    (* restore old values *)
    theInt1:= mdlg.oldInt1;  theInt2:= mdlg.oldInt2;
  END DoCancel;
  
  
  PROCEDURE DoMyButton;
  BEGIN 
    (*. your statements .*)
    (*. e.g. .*)
    SelectForOutput(mdlg.myEntryForm);
    SetPen(mdlg.middle, mdlg.yTxtLn);
    WriteString("Hello");
  END DoMyButton;
  

      
  PROCEDURE DoModalDialog;
    CONST leftMarg = 14; lineH = 22; butWidth = 75; intFW = 6;
    VAR x,y: INTEGER;
  BEGIN 
    (* save old values *)
    mdlg.oldInt1:=theInt1;  
    mdlg.oldInt2:=theInt2;  
    (* determine size and position of modal dialog (entry form) and open window *)
    mdlg.wf.w:=360;  mdlg.wf.h:=150;
    mdlg.wf.x := (BackgroundWidth()-mdlg.wf.w) DIV 2;
    mdlg.wf.y := (BackgroundHeight()-mdlg.wf.h) DIV 2;
    CreateModalWindow(mdlg.myEntryForm, SingleFrameShadowed,
                      WithoutScrollBars, mdlg.wf, AutoRestoreProc);
    SetWindowFont(Chicago, 12, FontStyle{}); 
    mdlg.middle := (mdlg.wf.w-6*CellWidth()) DIV 2;
    (* display editing fields for each variable you wish to edit *)
    x := leftMarg; y := mdlg.wf.h-lineH;
    SetPen(x,y); WriteString("Integer 1 (theInt1)");
    x := mdlg.middle;
    MakeIntField(mdlg.myEntryForm, mdlg.intF1, x, y, intFW, theInt1, 0, 10);
    x := leftMarg; y := y - lineH;
    SetPen(x,y); WriteString("Integer 2 (theInt2)");
    x := mdlg.middle;
    MakeIntField(mdlg.myEntryForm, mdlg.intF2, x, y, intFW, theInt2, MIN(INTEGER), MAX(INTEGER));
    x := leftMarg; y := y - lineH-11; mdlg.yTxtLn := y;
    MakePushButton(mdlg.myEntryForm, mdlg.myBut, x, y, butWidth DIV CellWidth(), 
                   "Say it", DoMyButton);
    (*. define your own fields ad libitum .*)
    (*. ... .*)
    (* make standard Ok and Cancel buttons *)                              
    MakePushButton(mdlg.myEntryForm, mdlg.okBut, mdlg.wf.w-butWidth-leftMarg, lineH,
                   butWidth DIV CellWidth(), okButtonText, DoOk);
    UseAsDefaultButton(mdlg.okBut);
    MakePushButton(mdlg.myEntryForm, mdlg.cancelBut, leftMarg, lineH,
                   butWidth DIV CellWidth(), cancelButtonText, DoCancel);
    (* place cursor into e.g. the first editable field or wherever you wish *)                                
    SelectField(mdlg.intF1);
    (* fire up the modal dialog *)
    UseWindowModally(mdlg.myEntryForm, mdlg.acceptIt, mdlg.cancelled);
    (* dialog has finished, clean up *)
    RemoveWindow(mdlg.myEntryForm);
    mdlg.entryFormOk := NOT mdlg.cancelled;
    IF mdlg.entryFormOk AND mdlg.acceptIt THEN
      (*. do postprocessing if necessary .*)
    END(*IF*);
  END DoModalDialog;

7 - Keyboard Usage and Portable Programing


  (*------------------------------------------------------*)
  (*=====   Programing special characters portably   =====*)
  (*------------------------------------------------------*)
  
   
  FROM DMKeyChars IMPORT ProgrammedOn, ComputerPlatform, BestCH;
  
  VAR bullet: CHAR;
  
  ProgrammedOn(Mac);
  bullet := BestCH(245C); (* = CHR(165) = "•" (on Mac only) *)

     (* NOTE: don't program  bullet := BestCH("•"), since some transfer
     techniques such as WINFTP (Windows ftp) alter the source code 
     when transfering it from one machine to the other *)

     
  (*-----------------------------*)
  (*=====   Key shortcuts   =====*)
  (*-----------------------------*)
     
   
  FROM DMMaster IMPORT AddKeyboardHandler, InspectKey, KeyAccepted;
  FROM DMKeyChars IMPORT command, capslock, shift;
   
  PROCEDURE MyKeyboardHandler;
    VAR ch: CHAR; m: BITSET;
  BEGIN (* MyKeyboardHandler *)
    InspectKey(ch, m); ch := CAP(ch); (* case insensitive *)
    IF (m={command,shift}) AND (ch="H") THEN
      KeyAccepted;
      (*. *** do what you want *** .*)
    END(*IF*);
  END MyKeyboardHandler;
  
  
  PROCEDURE InstallMyKeyboardHandler;
    CONST lowPriority = (MAX(INTEGER) DIV 4) * 3;
  BEGIN (* InstallMyKeyboardHandler *)
    AddKeyboardHandler(MyKeyboardHandler,lowPriority);
  END InstallMyKeyboardHandler;

  
  
  (*-----------------------------------*)
  (*=====   Portable programing   =====*)
  (*-----------------------------------*)
  

  FROM DMStrings IMPORT FindInString;
  FROM DMSystem IMPORT GetComputerName, ComputerSystem, SUN, IBMPC, 
    IBMRisc6000;


  PROCEDURE RunsOnAMac(): BOOLEAN;
    VAR cn: ARRAY [0..3] OF CHAR; macInName: BOOLEAN; fst,lst, cs: INTEGER;
  BEGIN (* RunsOnAMac *)
    GetComputerName(cn);
    macInName:= (CAP(cn[0])="M") AND (CAP(cn[1])="A") AND (CAP(cn[2])="C");
    fst := 0; lst := 0;
    macInName := macInName OR FindInString(cn,"Mac",fst,lst);
    cs := ComputerSystem();
    RETURN macInName OR (cs



8 - Strings


  (*----------------------------------*)
  (*=====   Extract substrings   =====*)
  (*----------------------------------*)

   
  FROM DMStrings IMPORT ExtractSubString;
  
  CONST atEOS = MAX(INTEGER) (* at End Of String*); delimiter = "|";
  VAR i: INTEGER; fromStr,subStr: ARRAY [0..hi] OF CHAR;
    
    i := 0; 
    REPEAT
      ExtractSubString(i,fromStr,subStr,delimiter);
      (*. *** do with substring subStr what you want *** .*)
    UNTIL i=atEOS;


    i := 0; ExtractSubString(i,fromStr,subStr,delimiter);
    WHILE (subStr[0]<>0C) DO
      (*. *** do with substring subStr what you want *** .*)
      ExtractSubString(i,fromStr,subStr,delimiter);
    END(*WHILE*);
 
    
  (*-----------------------------*)
  (*=====   Edit a string   =====*)
  (*-----------------------------*)
  
  
  FROM DMStrings IMPORT FindInString, CopyString;

  
  PROCEDURE ReplaceAllInString (VAR(*speed-up*) is: ARRAY OF CHAR; sub,rpl: ARRAY OF CHAR; 
                             VAR os: ARRAY OF CHAR);
    CONST stopAt0C = -1;
    VAR firstCh,lastCh,i,j: INTEGER;
  BEGIN (* ReplaceAllInString *)
    i := 0; j := 0; os[0] := 0C; firstCh := 0; lastCh := firstCh;
    WHILE FindInString(is,sub,firstCh,lastCh) DO
      CopyString(is,i,firstCh-i,os,j); 
      CopyString(rpl,0,stopAt0C,os,j);
      i := lastCh+1; firstCh := i;
    END(*WHILE*);
    CopyString(is,i,stopAt0C,os,j); 
  END ReplaceAllInString;
  
  ...
  
  ReplaceAllInString(old," ","_",new);
  ReplaceAllInString(old,"some","several",new);

9 - About

   
  (*-------------------------*)
  (*=====   Text Only   =====*)
  (*-------------------------*)
  
  FROM DMMenus IMPORT InstallAbout;
  FROM DMWindows IMPORT RectArea;
  FROM DMWindIO IMPORT SetPos, StringArea, GetPen, SetPen, 
    SetWindowFont, WindowFont, FontStyle, FontStyles, WriteString;
    
   CONST
    aboutWidth = 400;
    aboutHeight = 200;

  PROCEDURE AboutProc;
    CONST
      begLn = 2;
    VAR
      centerWidth,centerLine,leftMar: INTEGER;  
      
    PROCEDURE SetCenterWidth (w: INTEGER);
    BEGIN
      centerWidth := w;
    END SetCenterWidth;
    
    PROCEDURE SetCenterLine  (l: CARDINAL);
    BEGIN
      centerLine := l; SetPos(l,leftMar);
    END SetCenterLine;
  
    PROCEDURE WriteCenteredLn (s: ARRAY OF CHAR);
      VAR a: RectArea; bl,ss,xx,yy: INTEGER;
    BEGIN
      SetPos(centerLine,leftMar);
      StringArea(s,a,bl,ss);
      GetPen(xx,yy); SetPen((centerWidth-a.w) DIV 2,yy);
      WriteString(s);
      INC(centerLine); SetPos(centerLine,leftMar);
    END WriteCenteredLn;
    
  BEGIN (*AboutProc*)
    leftMar := 2;
    SetCenterWidth(aboutWidth);
    SetCenterLine(begLn);
    SetWindowFont( Geneva, 12, FontStyle{underline,bold} );
    WriteCenteredLn("M y P r o g");
    SetWindowFont( Geneva, 9, FontStyle{} );
    SetCenterLine(begLn+3);
    WriteCenteredLn("What it does...");
    WriteCenteredLn("");
    WriteCenteredLn("Programmed by FirstName LastName");
    WriteCenteredLn("© ETHZ   V1.1  (March/1999)");
    WriteCenteredLn("");
    WriteCenteredLn("This utility may be copied freely, but not for profit!");
    WriteCenteredLn("Our website: www.sysecol.ethz.ch/");
  END AboutProc;

  ...
  
  PROCEDURE InstallMenus;
  BEGIN 
     InstallAbout("About MyProg...",aboutWidth,aboutHeight,AboutProc);
     ...
  END InstallMenus;

  
  (*-------------------------------------------*)
  (*=====   Simple, Predefined Graphics   =====*)
  (*-------------------------------------------*)
  
  FROM DMWindIO IMPORT DisplayPredefinedPicture;
  
  CONST
    aboutWidth = 400;
    aboutHeight = 200;

  PROCEDURE AboutProc;
    CONST aboutPictID = 29801(*. actually ID of your picture, see e.g. ResEdit.*);
  BEGIN
    DisplayPredefinedPicture("",aboutPictID,aboutFrame);
  END AboutProc;
  
  ...
  
  PROCEDURE InstallMenus;
  BEGIN 
     InstallAbout("About MyProg...",aboutWidth,aboutHeight,AboutProc);
     ...
  END InstallMenus;

10 - Reporting on Date and Time


  FROM DMClock IMPORT Today, Now;
  FROM DMWindIO IMPORT WriteString, Write, WriteLn;
  FROM WriteDatTim IMPORT DateAndTimeRec, DateFormat, TimeFormat, 
    WriteDate, WriteTime; 

    
  PROCEDURE ReportDateAndTime;
    VAR dt: DateAndTimeRec;
    
    PROCEDURE GetDateAndTime(VAR dt: DateAndTimeRec);
    BEGIN
      Today (dt.year,dt.month,dt.day, dt.dayOfWeek);
      Now (dt.hour,dt.minute, dt.second);
    END GetDateAndTime;
    
    PROCEDURE RecordDateTime(s: ARRAY OF CHAR; dt: DateAndTimeRec);
    BEGIN
      WriteString(s);
      WriteDate(dt,Write,letMonth); WriteString(" at ");
      WriteTime(dt,Write,brief24hSecs); WriteLn;
    END RecordDateTime;
    
  BEGIN (*ReportDateAndTime*)
    GetDateAndTime(dt);
    RecordDateTime("SomethingAsOf",dt);
  END ReportDateAndTime;


  RAMSES@env.ethz.ch Last modified 1/30/23 [Top of page]   

Modula-2 website ring
List all    |    <<  Prev    |    Next  >>    |    Join