My caclulator

By Relurk_ on Dec 09, 2008

right click and select calculator in the menu and put in any 2 numbers and select a function.

menu * {
  Calculator:/calc
}
alias Calc { dialog -md calc calc }
dialog calc {
  title "Calculator"
  size -1 -1 116 62
  option dbu
  edit "", 1, 6 12 49 10, autohs
  edit "", 2, 66 12 49 10, autohs
  text "First number", 3, 7 3 48 8, center
  text "Second number", 4, 66 3 48 8, center
  button "Add", 5, 7 24 27 12
  box "Answer:", 6, 7 38 108 23
  button "Sub", 7, 34 24 27 12
  button "Mul", 8, 61 24 27 12
  button "Div", 9, 88 24 27 12
  edit "", 10, 9 46 102 10
}
on *:dialog:calc:sclick:*: {
  if ( $did == 5 ) { did -r $dname 10 | set %n1 $did(1).text | set %n2 $did(2).text | did -a $dname 10 $calc(%n1 + %n2) | HALT }
  if ( $did == 7 ) { did -r $dname 10 | set %n1 $did(1).text | set %n2 $did(2).text | did -a $dname 10 $calc(%n1 - %n2) | HALT }
  if ( $did == 8 ) { did -r $dname 10 | set %n1 $did(1).text | set %n2 $did(2).text | did -a $dname 10 $calc(%n1 * %n2) | HALT }
  if ( $did == 9 ) { did -r $dname 10 | set %n1 $did(1).text | set %n2 $did(2).text | did -a $dname 10 $calc(%n1 / %n2) | HALT }
}

Comments

Sign in to comment.
TheImrac   -  Dec 09, 2008

=) I actually didn't know dname was optional inside a dialog event. So you taught me something unknowingly. That would probably reduce some of my codes by 100s of characters. I always used $dname lol =P

 Respond  
Jonesy44   -  Dec 09, 2008

true lol, i edited the characters after :P but that'd work x]

 Respond  
TheImrac   -  Dec 09, 2008

Joensey you could also do

on *:dialog:calc:sclick:*: {
  if ($did isnum 6-9) { did -ra $dname 10 $iif($did(1) isnum && $did(2) isnum,$calc($did(1) $did($did) $did(2)),NaN) }
}
 Respond  
Jonesy44   -  Dec 09, 2008

Can be shortened to..

menu * {
  Calculator:calc 
}
alias calc { dialog -m calc calc }
dialog calc {
  title "Calculator"
  size -1 -1 116 62
  option dbu
  edit "", 1, 6 12 49 10, autohs
  edit "", 2, 66 12 49 10, autohs
  text "First number", 3, 7 3 48 8, center
  text "Second number", 4, 66 3 48 8, center
  box "Answer:", 5, 7 38 108 23
  button "+", 6, 7 24 27 12
  button "-", 7, 34 24 27 12
  button "*", 8, 61 24 27 12
  button "/", 9, 88 24 27 12
  edit "", 10, 9 46 102 10
}
on *:dialog:calc:sclick:*: {
  if ($did isnum 6-9) {
    var %sym = + - * /
    did -ra $dname 10 $iif($did(1) isnum && $did(2) isnum,$calc($did(1) $gettok(%sym,$calc($did - 5),32) $did(2)),NaN)
  }
}
 Respond  
Jonesy44   -  Dec 09, 2008

Nice "caclulator" LOL

Dev->Div, if you mean DIVIDE

 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.