home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 32 Periodic / 32-Periodic.zip / sdin9303.zip / VCALC.LST < prev   
File List  |  1993-03-13  |  3KB  |  71 lines

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