Big update since last version.
Click "Calculators" in the dialog to switch between Basic and Advanced versions. There is also a "Help" menu to explain what some of the button are and/or do.
Update: Shortened the code by around 50 lines.
Update: Added M ( memory ), MRC ( memory recall ) and MRC ( memory clear ).
Update: Replaced " $read(memory.txt,0) " with " $exists(memory.txt) " since the " $read(memory.txt,0) " was having issues when the number saved had a " - " or " . " in the first position.
Update: The "Sqrt" button on the Advanced Calculator part did not work at all. There was nothing in the script assigned to that button. It now works as it should.
menu * {
Calculators: { Calculator }
}
alias calculator {
dialog $iif($dialog(calc),-v,-mbp) calc calc
did -h calc 23-33,200,220,300,220,440-454
did -b calc 300
dialog -b calc -1 -1 105 130
dialog -t calc Basic Calculator
}
dialog calc {
title "Calculator"
size -1 -1 105 130
option dbu
menu "&Calculators", 1000
menu "&Help", 777
item "&Help", 778
item "&Basic", 2000, 1000
item "&Advanced", 3000, 1000
box "", 2, 2 0 101 127
edit "", 3, 5 19 95 10
button "M", 100, 5 4 15 15
button "MRC", 101, 45 4 15 15
button "MC", 102, 85 4 15 15
box "", 200, 2 0 165 127
edit "", 300, 5 19 158 10
button "1", 4, 5 30 15 15
button "2", 5, 32 30 15 15
button "3", 6, 58 30 15 15
button "4", 7, 85 30 15 15
button "5", 8, 5 50 15 15
button "6", 9, 32 50 15 15
button "7", 10, 58 50 15 15
button "8", 11, 85 50 15 15
button "9", 12, 5 70 15 15
button "0", 13, 32 70 15 15
button "+", 14, 58 70 15 15
button "-", 15, 85 70 15 15
button "*", 16, 5 90 15 15
button "/", 17, 32 90 15 15
button "^", 18, 58 90 15 15
button ".", 19, 85 90 15 15
button "Calculate", 20, 5 110 30 15, default
button "Clear", 21, 70 110 30 15
button "Sqrt", 22, 45 110 15 15
button "Sqrt", 220, 148 110 15 15
button "COS", 23, 108 30 25 15
button "ACOS", 24, 138 30 25 15
button "SIN", 25, 108 50 25 15
button "ASIN", 26, 138 50 25 15
button "TAN", 27, 108 70 25 15
button "ATAN", 28, 138 70 25 15
button "ABS", 29, 108 90 15 15
button "Log", 30, 128 90 15 15
button "Rnd", 31, 148 90 15 15
button "(", 32, 108 110 15 15
button ")", 33, 128 110 15 15
text "Symbols and Functions", 440, 5 3 160 10, center
edit "( ) <-- Parentheses", 441, 5 12 160 10, center read
edit " / <-- Divide(d) by. Ex: 3/3 is 3 divided 3.", 442, 5 23 160 10, center read
edit " . <-- Decimal Point.", 443, 5 34 160 10, center read
edit "^ <-- Raised to # Ex: 3^3 would be 3 raised to 3 ( or 3*3*3)", 444, 5 45 160 10, center read
edit "COS = Cosine of a number.", 445, 5 56 160 10, center read
edit "ACOS = ArcConsine of a number.", 446, 5 67 160 10, center read
edit "SIN = Sine of a number.", 447, 5 78 160 10, center read
edit "ASIN = ArcSine of a number.", 448, 5 89 160 10, center read
edit "TAN = Tangent of a number.", 449, 5 100 160 10, center read
edit "ATAN = ArcTangent of a number.", 450, 5 111 160 10, center read
edit "ABS = Absolute Value of a number.", 451, 5 122 160 10, center read
edit "Log = Logarithm of a number.", 452, 5 133 160 10, center read
edit "Rnd = Rounds number to a certain decimal point. Default is 5.", 453, 5 144 160 10, center read
edit "Sqrt = Square Root of a number.", 454, 5 155 160 10, center read
edit "M = Memory", 455, 5 166 160 10, center read
edit "MRC = Memory Recall", 456, 5 177 160 10, center read
edit "MC = Memory Clear", 457, 5 188 160 10, center read
}
on *:dialog:calc:*:*: {
if ($devent == init) {
if ($exists(memory.txt)) { did -e $dname 101-102 | did -b $dname 100 }
if (!$exists(memory.txt)) { did -b $dname 101-102 | did -e $dname 100 }
}
if ($devent == sclick) {
$iif($did(300).enabled, did -f $dname 300, did -f $dname 3)
if ($did == 4) { $iif($did(300).enabled, did -a $dname 300 1, did -a $dname 3 1) }
if ($did == 5) { $iif($did(300).enabled, did -a $dname 300 2, did -a $dname 3 2) }
if ($did == 6) { $iif($did(300).enabled, did -a $dname 300 3, did -a $dname 3 3) }
if ($did == 7) { $iif($did(300).enabled, did -a $dname 300 4, did -a $dname 3 4) }
if ($did == 8) { $iif($did(300).enabled, did -a $dname 300 5, did -a $dname 3 5) }
if ($did == 9) { $iif($did(300).enabled, did -a $dname 300 6, did -a $dname 3 6) }
if ($did == 10) { $iif($did(300).enabled, did -a $dname 300 7, did -a $dname 3 7) }
if ($did == 11) { $iif($did(300).enabled, did -a $dname 300 8, did -a $dname 3 8) }
if ($did == 12) { $iif($did(300).enabled, did -a $dname 300 9, did -a $dname 3 9) }
if ($did == 13) { $iif($did(300).enabled, did -a $dname 300 0, did -a $dname 3 0) }
if ($did == 14) { $iif($did(300).enabled, did -a $dname 300 +, did -a $dname 3 +) }
if ($did == 15) { $iif($did(300).enabled, did -a $dname 300 -, did -a $dname 3 -) }
if ($did == 16) { $iif($did(300).enabled, did -a $dname 300 *, did -a $dname 3 *) }
if ($did == 17) { $iif($did(300).enabled, did -a $dname 300 /, did -a $dname 3 /) }
if ($did == 18) { $iif($did(300).enabled, did -a $dname 300 ^, did -a $dname 3 ^) }
if ($did == 19) { $iif($did(300).enabled, did -a $dname 300 ., did -a $dname 3 .) }
if ($did == 20) { $iif($did(300).enabled, did -ra $dname 300 $calc($did(300)), did -ra $dname 3 $calc($did(3)) ) }
if ($did == 21) { $iif($did(300).enabled, did -r $dname 300, did -r $dname 3) }
if ($did == 22) { did -ra $dname 3 $sqrt($did(3)) }
if ($did == 220) { did -ra $dname 300 $sqrt($did(300)) }
if ($did == 23) { $iif($did(300).enabled, did -ra $dname 300 $cos($did(300)), did -ra $dname 3 $cos($did(3)) ) }
if ($did == 24) { $iif($did(300).enabled, did -ra $dname 300 $acos($did(300)), did -ra $dname 3 $acos($did(3)) ) }
if ($did == 25) { $iif($did(300).enabled, did -ra $dname 300 $sin($did(300)), did -ra $dname 3 $sin($did(3)) ) }
if ($did == 26) { $iif($did(300).enabled, did -ra $dname 300 $asin($did(300)), did -ra $dname 3 $asin($did(3)) ) }
if ($did == 27) { $iif($did(300).enabled, did -ra $dname 300 $tan($did(300)), did -ra $dname 3 $tan($did(3)) ) }
if ($did == 28) { $iif($did(300).enabled, did -ra $dname 300 $atan($did(300)), did -ra $dname 3 $atan($did(3)) ) }
if ($did == 29) { $iif($did(300).enabled, did -ra $dname 300 $abs($did(300)), did -ra $dname 3 $abs($did(3)) ) }
if ($did == 30) { $iif($did(300).enabled, did -ra $dname 300 $log($did(300)), did -ra $dname 3 $log($did(3)) ) }
if ($did == 31) { $iif($did(300).enabled, did -ra $dname 300 $round($did(300)), did -ra $dname 3 $round($did(3)) ) }
if ($did == 32) { $iif($did(300).enabled, did -a $dname 300 $chr(40), did -a $dname 3 $chr(40) ) }
if ($did == 33) { $iif($did(300).enabled, did -a $dname 300 $chr(41), did -a $dname 3 $chr(41) ) }
if ($did == 100) {
if ($did(3).enabled) {
if (($left($did(3).text,1) == -) || ($left($did(3).text,1) == .) || ($left($did(3).text,1) isnum)) {
if (($did(3).text isnum) && ($count($did(3).text,$chr(46)) <= 1)) {
$iif($exists(memory.txt), did -b $dname 100, did -e $dname 101-102)
if (!$exists(memory.txt)) { write memory.txt $did(3) | halt }
}
else { echo 4 -a That is not a valid entry to use with M. | halt }
}
else { echo 4 -a That is not a valid entry to use with M. | halt }
}
if ($did(300).enabled) {
if (($left($did(300).text,1) == -) || ($left($did(300).text,1) == .) || ($left($did(300).text,1) isnum)) {
if (($did(300).text isnum) && ($count($did(300).text,$chr(46)) <= 1)) {
$iif($exists(memory.txt), did -b $dname 100, did -e $dname 101-102)
if (!$exists(memory.txt)) { write memory.txt $did(300) | halt }
}
else { echo 4 -a That is not a valid entry to use with M. | halt }
}
else { echo 4 -a That is not a valid entry to use with M. | halt }
}
}
if ($did == 101) {
if (!$exists(memory.txt)) { did -b $dname 101 | halt }
else { $iif($did(3).enabled, did -ra $dname 3 $read(memory.txt,t,1), did -ra $dname 300 $read(memory.txt,t,1) ) }
}
if ($did == 102) { .remove memory.txt | did -b $dname 101,102 | did -e $dname 100 }
}
if ($devent == menu) {
if ($did == 2000) {
;Basic Calculator
dialog -t calc Basic Calculator
dialog -bs calc -1 -1 105 140
did -h calc 23-33,200,220,300,220,440-457
did -br calc 300
did -e calc 3
did -v calc 2-22,100-102
}
if ($did == 3000) {
;Advanced Calculator
dialog -t calc Advanced Calculator
dialog -bs calc -1 -1 170 140
did -h calc 2,3,20-22,440-457
did -br calc 3
did -e calc 300
did -v calc 4-21,23-33,100-102,200,220,300
}
if ($did == 778) {
;Calculator Help
dialog -t calc Calculator Help
dialog -bs calc -1 -1 170 212
did -r calc 3,300
did -h calc 2-33,100-102,200,220,300
did -v calc 440-457
}
}
}
if ($did == 4) { did -a $dname 3 1 }
if ($did == 5) { did -a $dname 3 2 }
if ($did == 6) { did -a $dname 3 3 }
if ($did == 7) { did -a $dname 3 4 }
You can shrink the script by making the \'$did\'s which are setting numbers into one line (on two occasions) like this example (for the above section):
if ($did >= 4) && ($did <= 7) did -a $dname 3 $calc($did - 3)
You could use $right($calc($did - 3),1) for $did up to 13 in this case (that would return 0). :)
It\'s better now, but while testing it I decided to make an ammendment to the bit I suggested to you
alias calculator {
/dialog $iif($dialog(calc),-v,-md) calc calc
}
alias calculator2 {
/dialog $iif($dialog(calc2),-v,-md) calc2 calc2
}
I added the -d switch so now the calculators open as desktop windows, I find this better so I can keep the calculator window minimised at the bottom so I can open it up without opening the mIRC window.