;Simulates Calculator Using #Include Files   v1.00

;*******************************************************************************
;*                                                                             *
;*Calc.was  ver.  1.0                                                          *
;* Written by:  Symantec ASPECT Assist                                       *
;*                                                                           *                                                                             
;* This script file will give the user the option of either capturing data   *
;* in half hour increments, or in 24 hour increments. The Capture file will  *
;* close after a predefined period of inactivity on the port.                *
;*                                                                           *
;* This ASPECT script is intended only as a sample of ASPECT programming.    *
;* Symantec makes no warranty of any kind, express or implied, including     *
;* without limitation, any warranties of merchantability and/or fitness      *
;* for a particular purpose.  Use of this program is at your own risk.       *
;*                                                                           *
;* Technical Support is not provided on this script.                         *                                                                          *
;*****************************************************************************


;*******************************************************************************
;*   INCLUDED FILES                                                            *
;*   This script requires the programs listed in this section to compile.      *
;*******************************************************************************
#Include "MATHPACK.INC"  ;This file contains the math functions


;*******************************************************************************
;*                                                                             *
;* MAIN                                                                        *
;* The Main procedure displays the dialog box whick has buttons and edit boxes *
;* to resemble a calculator.  Main then calls the INCLUDED Math_Pack to        *
;* perform the arithmetic operations.  The result is displayed in the Dialog   *
;* Box.                                                                        *
;*                                                                             *
;* Calls: Math_Pack                                                           *
;* Modifies globals: none                                                      *
;*                                                                             *
;*******************************************************************************
proc main               ;Beginning of processing
string value            ;String to hold result of math operation.
string Op_str           ;String to hold the Operator selected.
float num1,num2         ;Floating point variables to hold numbers
integer Event           ;Integer holding Id of Dialog Control.


;* Create the Graphic Calculator on the Screen.
;* Each pushbutton is labeled with a number, operator, or Clear.

   dialogbox 0 28 52 161 164 2 "Aspect Calculator" 
      pushbutton 1 13 84 26 14 "1"        ;first of Aspect calculator buttons
      pushbutton 2 46 84 26 14 "2" 
      pushbutton 3 78 84 26 14 "3" 
      pushbutton 4 13 63 26 14 "4" 
      pushbutton 5 46 63 26 14 "5" 
      pushbutton 6 78 63 26 14 "6" 
      pushbutton 7 13 42 26 14 "7" 
      pushbutton 8 46 42 26 14 "8" 
      pushbutton 9 78 42 26 14 "9" 
      pushbutton 10 12 106 60 14 "0" 
      pushbutton 11 114 41 30 14 "+" 
      pushbutton 12 114 63 30 14 "-" 
      pushbutton 13 114 84 30 14 "*" 
      pushbutton 14 114 106 30 14 "/" 
      editbox 15 15 10 137 17 Value       ;The "Window" of the calculator.
      pushbutton 16 78 106 26 14 "=" 
      pushbutton 17 85 133 60 14 "E&xit"  ;Button to exit the Script.
      pushbutton 20 14 133 60 14 "Clear" 
   enddialog 

   Value=""                ;Start with a Blank Window in calculator.
   Event=0
   while 1                 ;Loop forever.
      dlgEvent 0 Event     ;Get dialog Event and equals the id of button pressed.
      switch Event         ;Evaluate the EventID.
         case 0            ;No EventID occurred.
         endcase
         case 1            ;One button pressed
            strcat Value "1" ;Put 1 in the Calculator Window at end of String.
         endcase
         case 2           
            strcat Value "2" ;Put 2 in the Calculator Window at end of String.
         endcase
         case 3
            strcat Value "3" ;Put 3 in the Calculator Window at end of String.
         endcase
         case 4
            strcat Value "4" ;Put 4 in the Calculator Window at end of String.
         endcase
         case 5
            strcat Value "5" ;Put 5 in the Calculator Window at end of String.
         endcase
         case 6
            strcat Value "6" ;Put 6 in the Calculator Window at end of String.
         endcase
         case 7
            strcat Value "7" ;Put 7 in the Calculator Window at end of String.
         endcase
         case 8
            strcat Value "8" ;Put 8 in the Calculator Window at end of String.
         endcase
         case 9
            strcat Value "9" ;Put 9 in the Calculator Window at end of String.
         endcase
         case 10
            if Not nullstr Value ; See if Window already contans a number.
               strcat Value "0"  ; If there already is some number, add zero
            endif                ; Otherwise don't start a number with a zero.
         endcase
         case 11
            Op_str="+"          ;Assign the operator to string.
            atof Value Num1     ;Change the string to a number
            Value=""            ;Clear the Calculator Window.
         endcase
         case 12
            Op_str="-"          ;Assign the operator to string.
            atof Value Num1     ;Change the string to a number
            Value=""            ;Clear the Calculator Window.
         endcase
         case 13
            Op_str="*"           ;Assign the operator to string.
            atof Value Num1      ;Change the string to a number
            Value=""             ;Clear the Calculator Window.
         endcase
         case 14
            Op_str="/"          ;Assign the operator to string.
            atof Value Num1     ;Change the string to a number
            Value=""            ;Clear the Calculator Window.
         endcase
         case 16
            atof Value Num2     ;Change the string to a number
            Value=""               ;Clear the Calculator Window.
      ; Call the Included Math_Pack Procedure
            Math_Pack(Num1,Num2,Op_str,&Value)
      ;The above '&' prior to the variable Value allows its value to be
      ; changed in the procedure called, and to return that change here.
         endcase
         case 17
            exitwhile           ;EXIT Button pressed. Leave the While 1 loop.
         endcase
         case 20
            Value=""            ;Clear Button pressed, clear calculator Window.
         endcase 
      endswitch   
      dlgupdate 0 15     ;Update the dialog window each time through the loop.
   endwhile         
endproc                    ;End of Proc Main
