calculator dialog

By Stewie1k94 on Sep 10, 2011

to use open up the dialog through the menu

and click the buttons and click calculate

i will try and update and make it better soon

have fun ;)

$comma alias by: FiberOPtics

alias -l comma {
  var %a, %b = $regsub($ticks,$$1,/\G([+-]?\d+?)(?=(?:\d{3})++(?=\.\d++$|$))/g,\1 $+ $chr(44),%a)
  return %a
}
dialog calc {
  title "Dialog Calculator"
  size -1 -1 150 112
  option dbu
  box "Calculator Controls" 1, 5 5 140 60
  box "Calculation/Awnser" 2, 5 67 140 38
  button "1" 3, 9 14 20 10
  button "2" 4, 31 14 20 10
  button "3" 5, 52 14 20 10
  button "4" 6, 9 26 20 10
  button "5" 7, 31 26 20 10
  button "6" 8, 52 26 20 10
  button "7" 9, 9 38 20 10
  button "8" 10, 31 38 20 10
  button "9" 11, 52 38 20 10
  button "0" 12, 9 50 42 10
  button "k" 13, 78 14 20 10
  button "m" 14, 99 14 20 10
  button "b" 15, 120 14 20 10
  button "." 16, 52 50 20 10
  button "+" 17, 78 26 20 10
  button "-" 18, 99 26 20 10
  button "*" 19, 120 26 20 10
  button "/" 20, 78 37 20 10
  button "Clear All" 21, 99 37 41 10
  edit "" 22, 10 75 130 12, autohs read multi
  button "Calculate" 23, 10 89 130 10
}
menu * {
  Calculator:{ 
    dialog $iif($dialog(calc),-v,-md) calc calc
  }
}
alias calc { 
  dialog -mt calc calc 
}
on *:dialog:calc:sclick:19:{ did -a calc 22 * }
on *:dialog:calc:sclick:18:{ did -a calc 22 - }
on *:dialog:calc:sclick:9:{ did -a calc 22 7 }
on *:dialog:calc:sclick:10:{ did -a calc 22 8 }
on *:dialog:calc:sclick:11:{ did -a calc 22 9 }
on *:dialog:calc:sclick:17:{ did -a calc 22 + }
on *:dialog:calc:sclick:6:{ did -a calc 22 4 }
on *:dialog:calc:sclick:7:{ did -a calc 22 5 }
on *:dialog:calc:sclick:8:{ did -a calc 22 6 }
on *:dialog:calc:sclick:3:{ did -a calc 22 1 }
on *:dialog:calc:sclick:4:{ did -a calc 22 2 }
on *:dialog:calc:sclick:5:{ did -a calc 22 3 }
on *:dialog:calc:sclick:12:{ did -a calc 22 0 }
on *:dialog:calc:sclick:16:{ did -a calc 22 . }
on *:dialog:calc:sclick:13:{ did -a calc 22 k }
on *:dialog:calc:sclick:14:{ did -a calc 22 m }
on *:dialog:calc:sclick:15:{ did -a calc 22 b }
on *:dialog:calc:sclick:21:{ did -r calc 22 }
on *:dialog:calc:sclick:20:{ did -a calc 22 / }
on *:dialog:calc:sclick:23:{ 
  if (!$did(22)) { 
    noop $input(Please specify a calculation in the edit box and click calculate,w,Warning!)
  }
  else {
    did -ra calc 22 $comma($calc($replace($remove($did(22),$chr(44)),pi,$pi,m,000000,k,000,b,000000000)))  
  }
}

Comments

Sign in to comment.
Stewie1k94   -  Jun 23, 2012

@Warriorii - Updated. :)

 Respond  
Warriorii   -  Jun 22, 2012

Nice job, the only problem is if you put in a formula of 25/2 it will give u the answer 13 instead of 12.5

 Respond  
Protheus   -  Nov 27, 2011

nvm i got it

 Respond  
Protheus   -  Nov 27, 2011

question: im doing this in DCX. So my calculate button is like this: xdid -ra pscalc 1 $calc($xdid(pscalc, 1)) but i get an invalid argument error. Help?

 Respond  
_Dean_   -  Sep 11, 2011

its always a good comment posting alternative ways to do it

 Respond  
jaytea   -  Sep 11, 2011

not that i would recommend it, but here's a funny little method just fyi:

dialog calc {
  ...
  button "/" 47, 25 14 15 10
  button "*" 42, 40 14 15 10
  button "-" 45, 55 14 15 10
  button "7" 55, 10 25 15 10 
  button "8" 56, 25 25 15 10
  button "9" 57, 40 25 15 10
  button "+" 43, 55 25 15 21
  button "4" 52, 10 36 15 10
  button "5" 53, 25 36 15 10
  button "6" 54, 40 36 15 10
  button "1" 49, 10 47 15 10
  button "2" 50, 25 47 15 10
  button "3" 51, 40 47 15 10
  button "0" 48, 10 58 30 10
  button "." 46, 40 58 15 10
  button "k" 107, 10 69 15 10
  button "m" 109, 25 69 15 10
  button "b" 98, 40 69 15 10
  ...
}

on *:dialog:calc:sclick:42-109:{ did -a calc 19 $chr($did) }

edit: haha, just realized the buttons' text are precisely what you want to add to the editbox. a range check + $did($did).text would also suffice, and would be much more sensible than renumbering your controls:

on *:dialog:calc:sclick:3-12,14-18,22-24:{ did -a calc 19 $did($did) }
 Respond  
Jethro   -  Sep 11, 2011

It's hard to make a scientific, foolproof calculator out of MSL. The closest I've gotten to is socket through Google's calculator. Even so, Google's is not 100% scientific and will run into problem with some complex math calculations. Nothing's guaranteed.

 Respond  
_Dean_   -  Sep 10, 2011

as Jethro said, i think that use a $replacex is better
i added the /
since on your original code, you didnt put the sclick for $did 3

on *:dialog:calc:sclick:*:{ 
  if ($did isnum 3-12) {  
    did -a calc 19 $replacex($did,3,/,4,*,5,-,6,7,7,8,8,9,9,+,10,4,11,5,12,6)
  }
  if ($did isnum 14-18) { did -a calc 19 $replacex($did,14,1,15,2,16,3,17,0,18,.) }
  if ($did isnum 22-24) { did -a calc 19 $replacex($did,22,k,23,m,24,b) }
  if ($did == 25) { did -r calc 19 }
  if ($did == 20) {
    if (!$did(19)) { noop $input(Please specify a calculation in the edit box and click calculate,w,Warning!) }
    else {
      did -ra calc 19 $bytes($calc($replace($did(19),k,000,m,000000,b,000000000)),b))
    }
  }
}

this calculator has no accuracy, since if you use 7.3/2 it will return 4

 Respond  
troll   -  Sep 10, 2011

nice br0

 Respond  
Stewie1k94   -  Sep 10, 2011

i updated it so that it gives the calculation in the same box the sum is put in to also made a del button so u can erase the sum and re input it

 Respond  
troll   -  Sep 10, 2011

kkkkkkk

 Respond  
troll   -  Sep 10, 2011

k00l

 Respond  
Stewie1k94   -  Sep 10, 2011

thanks for your suggestion again Jethro :)

 Respond  
Jethro   -  Sep 10, 2011

I was aiming for one dialog event instead of one per each. It's just an example only. I think you could do it with $replacexcs() too, which will make it a lot shorter.

 Respond  
Dani_l11   -  Sep 10, 2011

where's the regexmatch?

also why add if ($devent == sclick) {

just using on :dialog:calc:sclick::{ 's shorter

 Respond  
Jethro   -  Sep 10, 2011

You can do it with one event like this:

on *:dialog:calc:*:*:{
  if ($devent == sclick) {
    goto $did
    :3 | did -a calc 19 / | halt
    :4 |did -a calc 19 * | halt
    :5 | did -a calc 19 - | halt
    :6 | did -a calc 19 7 | halt
    :7 | did -a calc 19 8 | halt
    :8 | did -a calc 19 9 | halt
    :9 | did -a calc 19 + | halt
    :10 | did -a calc 19 4 | halt
    :11 | did -a calc 19 5 | halt
    :12 | did -a calc 19 6 | halt
    :14 | did -a calc 19 1 | halt
    :15 | did -a calc 19 2 | halt
    :16 | did -a calc 19 3 | halt
    :17 | did -a calc 19 0 | halt
    :18 | did -a calc 19 . | halt
    :22 | did -a calc 19 k | halt
    :23 | did -a calc 19 m | halt
    :24 | did -a calc 19 b | halt
    :20 
    if (!$did(19)) { noop $input(Please specify a calculation in the edit box and click calculate,w,Warning!) }
    else did -a calc 21 $bytes($calc($replace($did(19),k,000,m,000000,b,000000000)),b))
  }
  :error | reseterror
}
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.