home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 32 Periodic / 32-Periodic.zip / sdin9303.zip / VCALC.CMD < prev    next >
OS/2 REXX Batch file  |  1993-03-13  |  3KB  |  71 lines

  1. /* VREXX simple calculator program  */
  2. /* San Diego OS/2 Newsletter        */
  3. /* March 1993 edition               */
  4.  
  5. /* Program Initialization */
  6.  
  7.   CALL RxFuncAdd "VInit", "VREXX", "VINIT"          /* Add VInit function to attach to VREXX */
  8.   initcode = VInit()                                /* Initialize VREXX */
  9.   IF initcode = "ERROR" THEN SIGNAL VREXXCleanup    /* Exit program if VInit() failed */
  10.  
  11.   SIGNAL ON FAILURE NAME VREXXCleanup               /* If the program fails or stops for any    */
  12.   SIGNAL ON HALT NAME VREXXCleanup                  /* reason, the VREXX cleanup must be done   */
  13.                                                     /* in order to leave VREXX in a known state */
  14.  
  15.   SIGNAL ON SYNTAX NAME SyntaxError     /* Syntax errors should only be triggered by bad  */
  16.                                         /* user input, so when one happens, tell the user */
  17.                                         /* the math expression was bad.                   */
  18.  
  19. /* Main Program */
  20.  
  21.   windowTitle = "VREXX Calculator 1.0"  /* Title of input window */
  22.   dialogWidth = 50                      /* Input dialog should be 50 characters wide */
  23.   buttonType = 3                        /* type 3 means use OK and CANCEL buttons */
  24.  
  25.  
  26. InputLoop:                              /* Label used for looping back to get more input */
  27.  
  28.   prompt.0 = 1                                                  /* Only one prompt string */
  29.   prompt.1 = CENTER( "Enter a math expression:", dialogWidth )  /* This is the prompt string. */
  30.   prompt.vstring = ""                                           /* No default expression */
  31.  
  32.   /* Get input from user */
  33.   button = VInputBox( windowTitle, prompt, dialogWidth, buttonType )
  34.  
  35.   expr = prompt.vstring                 /* Store the expression the user typed */
  36.  
  37.   IF button = "OK" THEN DO              /* If the OK button was pressed */
  38.       INTERPRET "result =" || expr      /* evaluate the expression */
  39.  
  40.       text.0 = 1                        /* and then show a one-line result */
  41.       text.1 = result                   /* in a message box on the screen */
  42.  
  43.       /* Show the message box */
  44.       CALL VMsgBox "Result of <" || expr || ">", text, 1
  45.  
  46.       SIGNAL InputLoop                  /* Go get the next expression */
  47.   END
  48.  
  49.   /* The OK button wasn't pressed, so exit the program. */
  50.  
  51. /* Program Exit */
  52. VREXXCleanup:
  53.    CALL VExit               /* Clean up the VREXX resources */
  54.    EXIT                     /* Terminate the program        */
  55.  
  56.  
  57. /***** ERROR HANDLERS *****/
  58.  
  59. /* Display an error message */
  60. SyntaxError:
  61.   SIGNAL ON SYNTAX NAME SyntaxError     /* Reinstall error handler */
  62.  
  63.   text.0 = 2                            /* Show a two line display */
  64.   text.1 = "Bad expression:"            /* of the mistake          */
  65.   text.2 = "  " || expr
  66.  
  67.   CALL VMsgBox "Error", text, 1         /* Show the message box with just an OK button */
  68.  
  69.   SIGNAL InputLoop                      /* Go back and get more input */
  70.  
  71.