Basic Calculator Script (FULL) - 13/03/03 12:35 AM
I wrote this today on March 12, 2003, my first foray (venture) into Dialogs, someone may find this useful.
My reasoning for doing it:
a) see how it could be done in mirc script
b) i'm a heavy gamer and I figure since I mirc open while i'm gaming might as well use it's cpu cycles for the calculator rather than starting another calc.exe process.
have fun.
My reasoning for doing it:
a) see how it could be done in mirc script
b) i'm a heavy gamer and I figure since I mirc open while i'm gaming might as well use it's cpu cycles for the calculator rather than starting another calc.exe process.
have fun.
Code:
;created by Roger Lamb ;lambroger@cox-internet.com ;March 12, 2003 using Mirc 6.03 dialog calculator_layout { ;properties for the whole layout title "Calculator" size -1 -1 140 108 ;end of properties for the whole layout ;output box edit "",40,1 1 139 20,right read ;hidden storage box edit "",41,1 1 139 20,right read hide ;hidden memory box edit "",42,1 1 139 20,right read hide ;1st row button "7",7,1 22 20 20,default button "8",8,21 22 20 20,default button "9",9,41 22 20 20,default ;2nd row button "4",4,1 42 20 20,default button "5",5,21 42 20 20,default button "6",6,41 42 20 20,default ;3rd row button "1",1,1 62 20 20,default button "2",2,21 62 20 20,default button "3",3,41 62 20 20,default ;4th row button "0",10,21 82 20 20,default ;functions button ".",11,71 82 20 20,default button "=",12,91 82 20 20,default button "+",13,71 22 20 20,default button "-",14,71 42 20 20,default button "*",15,91 42 20 20,default button "/",16,91 22 20 20,default button "CE",17,1 82 20 20,default button "AC",18,41 82 20 20,default button "M+",19,115 62 22 20,default button "M-",20,115 82 22 20,default button "MR",21,115 42 22 20,default button "MC",22,115 22 22 20,default button "-+",23,71 62 20 20,default text "",24,96 65 12 12,center } alias calc { if ( %calc_active ) { dialog -v calculator return } dialog -m calculator calculator_layout } menu * { - Tools .Calculator: /calc } alias read_data { ;ensure there is data if( !$did(calculator,40) ) return 0 return $did(calculator,40) } on 1:dialog:calculator:init:*: { set %calc_active 1 set %decimal 11 set %equal 12 set %add 13 set %subtract 14 set %multiply 15 set %divide 16 set %clear_entry 17 set %all_clear 18 set %memory_add 19 set %memory_sub 20 set %memory_recall 21 set %memory_clear 22 set %sign 23 } on 1:dialog:calculator:close:*: { unset %calc_active unset %decimal unset %equal unset %add unset %subtract unset %multiply unset %divide unset %clear_entry unset %all_clear unset %memory_add unset %memory_sub unset %memory_recall unset %memory_clear unset %sign unset %last_function unset %enter_again } on 1:dialog:calculator:sclick:*: { var %id = $did read_data var %calc_data = $result ;insert numbers and leave the routine if ( %id <= 10 ) { if ( %wipe_me ) { %calc_data = $chr(32) unset %wipe_me } %calc_data = %calc_data $+ $right(%id,1) did -o calculator 40 1 %calc_data return } if ( %id == 11 ) { if ( %wipe_me ) { %calc_data = 0 unset %wipe_me } %calc_data = %calc_data $+ . did -o calculator 40 1 %calc_data return } ;ok if we get here, then it's because one of the ;function buttons were pressed var %function = %id ;determine which function was accessed if ( %function == %clear_entry ) { did -r calculator 40 return } if ( %function == %sign ) { did -o calculator 40 1 $calc( $did(calculator,40) * -1 ) return } if ( %last_function && %calc_data && $did(calculator,41) ) || ( %function == %equal ) { if ( %last_function == %multiply ) %calc_data = $calc( $did(calculator,41) * %calc_data ) if ( %last_function == %add ) %calc_data = $calc( $did(calculator,41) + %calc_data ) if ( %last_function == %subtract ) %calc_data = $calc( $did(calculator,41) - %calc_data ) if ( %last_function == %divide ) %calc_data = $calc( $did(calculator,41) / %calc_data ) did -o calculator 40 1 %calc_data did -r calculator 41 unset %last_function if ( %function == %equal ) { set %wipe_me 1 return } } if ( %function == %all_clear ) { did -r calculator 40 did -r calculator 41 unset %last_function unset %wipe_me return } if ( %function == %memory_recall ) { %calc_data = $did(calculator,42) did -o calculator 40 1 %calc_data return } if ( %function == %memory_clear ) { did -r calculator 42 did -r calculator 24 return } if ( %function == %memory_sub ) { did -o calculator 42 1 $calc( $did(calculator,42) - %calc_data ) did -o calculator 24 1 M return } if ( %function == %memory_add ) { did -o calculator 42 1 $calc( $did(calculator,42) + %calc_data ) did -o calculator 24 1 M return } ;ok it was a math key ;store old value into hidden box did -o calculator 41 1 %calc_data ;set last function set %last_function %id ;set wipe flag for numbers set %wipe_me 1 }