home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / vxrun.zip / WINDOW1.VRX < prev    next >
Text File  |  1993-06-18  |  7KB  |  294 lines

  1. /*:VRX         Main
  2. */
  3. /*  Main
  4. */
  5. Main:
  6. /*  Process the arguments.
  7.     Get the parent window.
  8. */
  9.     parse source . calledAs .
  10.     parent = ""
  11.     argCount = arg()
  12.     argOff = 0
  13.     if( calledAs \= "COMMAND" )then do
  14.         if argCount >= 1 then do
  15.             parent = arg(1)
  16.             argCount = argCount - 1
  17.             argOff = 1
  18.         end
  19.     end
  20.     InitArgs.0 = argCount
  21.     if( argCount > 0 )then do i = 1 to argCount
  22.         InitArgs.i = arg( i + argOff )
  23.     end
  24.     drop calledAs argCount argOff
  25.  
  26. /*  Load the windows
  27. */
  28.     call VRInit
  29.     parse source . . spec
  30.     _VREPrimaryWindowPath = ,
  31.         VRParseFileName( spec, "dpn" ) || ".VRW"
  32.     _VREPrimaryWindow = ,
  33.         VRLoad( parent, _VREPrimaryWindowPath )
  34.     drop parent spec
  35.     if( _VREPrimaryWindow == "" )then do
  36.         call VRMessage "", "Cannot load window:" VRError(), ,
  37.             "Error!"
  38.         _VREReturnValue = 32000
  39.         signal _VRELeaveMain
  40.     end
  41.  
  42. /*  Process events
  43. */
  44.     call Init
  45.     signal on halt
  46.     do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
  47.         _VREEvent = VREvent()
  48.         interpret _VREEvent
  49.     end
  50. _VREHalt:
  51.     _VREReturnValue = Fini()
  52.     call VRDestroy _VREPrimaryWindow
  53. _VRELeaveMain:
  54.     call VRFini
  55. exit _VREReturnValue
  56.  
  57. VRLoadSecondary: procedure
  58.     name = arg( 1 )
  59.  
  60.     window = VRLoad( VRWindow(), VRWindowPath(), name )
  61.     call VRMethod window, "CenterWindow"
  62.     call VRSet window, "Visible", 1
  63.     call VRMethod window, "Activate"
  64. return window
  65.  
  66. /*:VRX         digit_Click
  67. */
  68. digit_Click:
  69.     number = VRGet( VRInfo( "Object" ), "Caption" )
  70.     call number_click number
  71. return
  72. /*:VRX         do_previous_operation
  73. */
  74. do_previous_operation:
  75.  
  76.     /* Check for an error state */
  77.     if( error_is_on = 1 ) then return
  78.  
  79.     /* Check if any numbers have been pressed */
  80.     if( new_number = 0 )then do
  81.         operand = arg( 1 )
  82.         return
  83.       end
  84.  
  85.     /* Get the current number on the screen */
  86.     display_current = VRGet( 'dt_display', 'Caption' )
  87.  
  88.     /* Do the previous operation with the previous number */
  89.     if( operand = '+' ) then
  90.         display = display_previous + display_current
  91.     else if( operand = '-' ) then
  92.         display = display_previous - display_current
  93.     else if( operand = '*' ) then
  94.         display = display_previous * display_current
  95.     else if( operand = '/' ) then do
  96.         if( display_current = 0 ) then do           /* Divide by zero error */
  97.             error_is_on = 1
  98.             call update_memory_display 'e'
  99.             display = 0
  100.           end
  101.         else
  102.             display = display_previous / display_current
  103.       end
  104.     else
  105.         display = display_current
  106.  
  107.     /* Update the operand */
  108.     operand = arg( 1 )
  109.     new_number = 0
  110.  
  111.     /* Update the display */
  112.     display_previous = display
  113.     start_new_display = 1
  114.     call update_display
  115.  
  116. return
  117. /*:VRX         Fini
  118. */
  119. Fini:
  120.     window = VRWindow()
  121.     call VRSet window, 'Visible', '0'
  122.     drop window
  123. return 0
  124. /*:VRX         Halt
  125. */
  126. Halt:
  127.     signal _VREHalt
  128. return
  129.  
  130. /*:VRX         Init
  131. */
  132. Init:
  133.     memory_total = 0
  134.     call pb_c_Click
  135.  
  136.     window = VRWindow()
  137.     call VRMethod window, 'CenterWindow'
  138.     call VRSet window, 'Visible', '1'
  139.     call VRMethod window, 'Activate'
  140.     drop window
  141. return
  142.  
  143.  
  144. /*:VRX         number_click
  145. */
  146. number_click:
  147.     /* Check for an error state */
  148.     if( error_is_on = 1 ) then
  149.         return
  150.  
  151.     num = arg( 1 )
  152.     new_number = 1
  153.  
  154.     if( start_new_display = 1 ) then do
  155.         start_new_display = 0
  156.         display = num
  157.  
  158.         if( num = '.' ) then  do    /* Check if the first character is a decimal */
  159.             display ='0.'
  160.             decimal_flag = 1
  161.           end
  162.         else
  163.             decimal_flag = 0
  164.  
  165.         if( num = '0' ) then        /* Check if the first character is a zero */
  166.             start_new_display = 1
  167.  
  168.         call update_display
  169.         return
  170.       end
  171.  
  172.     if( num = '.' ) then do
  173.         decimal_flag = 1
  174.         return
  175.       end
  176.  
  177.     if( decimal_flag = 1) then
  178.         display = display || num
  179.     else do
  180.         parse var display display'.'
  181.         display = display || num || '.'
  182.       end
  183.  
  184.     call update_display
  185. return
  186. /*:VRX         operator_Click
  187. */
  188. operator_Click:
  189.     handle = VRInfo( "Object" )
  190.     if handle \= "" then do
  191.         operator = VRGet( handle, "Caption" )
  192.         call do_previous_operation operator
  193.     end
  194. return
  195. /*:VRX         pb_c_Click
  196. */
  197. pb_c_Click:
  198.     display_previous = 0
  199.     display_current = 0
  200.     start_new_display = 1
  201.     operand = ''
  202.     display = 0
  203.     decimal_flag = 0
  204.     new_number = 1
  205.     error_is_on = 0
  206.     call update_display
  207.     call update_memory_display memory_total
  208. return
  209. /*:VRX         pb_ce_Click
  210. */
  211. pb_ce_Click:
  212.     if( error_is_on = 1 ) then return
  213.     display = 0
  214.     start_new_display = 1
  215.     call update_display
  216.     new_number = 1
  217. return
  218. /*:VRX         pb_mc_Click
  219. */
  220. pb_mc_Click:
  221.     if( error_is_on = 1 ) then return
  222.     memory_total = 0
  223.     call update_memory_display memory_total
  224. return
  225. /*:VRX         pb_mminus_Click
  226. */
  227. pb_mminus_Click:
  228.     if( error_is_on = 1 ) then return
  229.     memory_temp = VRGet( 'dt_display', 'Caption' )
  230.     memory_total = memory_total - memory_temp
  231.     call update_memory_display memory_total
  232.     start_new_display = 1
  233. return
  234. /*:VRX         pb_mplus_Click
  235. */
  236. pb_mplus_Click:
  237.     if( error_is_on = 1 ) then return
  238.     memory_temp = VRGet( 'dt_display', 'Caption' )
  239.     memory_total = memory_total + memory_temp
  240.     call update_memory_display memory_total
  241.     start_new_display = 1
  242. return
  243. /*:VRX         pb_mr_Click
  244. */
  245. pb_mr_Click:
  246.     if( error_is_on = 1 ) then return
  247.     display = memory_total
  248.     call update_display
  249.     start_new_display = 1
  250.     new_number = 1
  251. return
  252. /*:VRX         pb_percent_Click
  253. */
  254. pb_percent_Click:
  255.     display = display / 100
  256.     call update_display
  257. return
  258. /*:VRX         Quit
  259. */
  260. Quit:
  261.     window = VRWindow()
  262.     call VRSet window, 'Shutdown', '1'
  263.     drop window
  264. return
  265. /*:VRX         update_display
  266. */
  267. update_display:
  268.     /* Update the display area */
  269.     tmp = POS( 'E', display )
  270.     parse var display whole'.'fraction             /* Split into whole and fraction */
  271.  
  272.     if( new_number = 0 ) then
  273.         if( tmp = 0 ) then
  274.             fraction = strip( fraction, 'T', 0 )   /* Strip the trailing zeros from the fraction */
  275.  
  276.     display = whole || '.' || fraction             /* Concatenate the whole and fraction */
  277.     call VRSet 'dt_display', 'Caption', display
  278. return
  279. /*:VRX         update_memory_display
  280. */
  281. update_memory_display:
  282.     if( arg( 1 ) = 'e' ) then
  283.         call VRSet 'dt_memory', 'caption', 'E'
  284.     else if( arg( 1 ) = 0 ) then
  285.         call VRSet 'dt_memory', 'caption', ''
  286.     else
  287.         call VRSet 'dt_memory', 'caption', 'M'
  288. return
  289. /*:VRX         Window1_Close
  290. */
  291. Window1_Close:
  292.     call Quit
  293. return
  294.