Temperature Converter (F°C°K°)

By Kirby on Nov 24, 2008

Hi again.
This is my second dialog, and the first one that I have worked independently with.

Anyways, here it is!

Image

Usage:
Right-click on any menu and click "Temperature Converter", or type: /tempcon to open up the dialog.
Click on a temperature scale (Fahrenheit, Celsius, Kelvin) on each of the horizontal columns, which you want to convert one scale to another. (Look at top picture if you're confused)
Enter a digit into the top left edit-box, and click "Convert!"
Use "Clear!" to clear all calculations, and "Exit!" to exit out of the dialog.

Enjoy! :)

alias tempcon { dialog $iif($dialog(temperature),-v,-m) temperature temperature }

menu * {
  Temperature: tempcon
}

dialog temperature {
  title "Temperature Converter"
  size -1 -1 150 75
  option dbu
  text "From:", 100, 35 3 26 10, nowrap
  text "To:", 99, 105 3 26 10, nowrap
  text "=", 98, 73 16 3 5, nowrap
  edit "", 1, 17 11 50 10
  edit "", 2, 83 11 50 10, style disable
  list 3, 15 24 55 30, sort vsbar
  list 4, 80 24 55 30, sort vsbar
  button "Convert!", 5, 5 57 45 15
  button "Clear!", 6, 100 57 45 15
  button "Exit!", 7, 53 58 45 13
  check "Round #'s", 8, 58 47 35 10, nowrap
}

on *:dialog:temperature:*:*: {
  if ($devent == init) && ($did == 0) { did -b $dname 5-6 | did $iif($did(8).state == 1,-c,-u) $dname 8 | didtok $dname 3-4 32 Fahrenheit Celsius Kelvin }
  if ($devent == sclick) {
    if ($did(1).edited) && ($did(3).sel) && ($did(4).sel) { did -e $dname 5 }
    if ($did == 5) {
      if ($did(1) isalpha) { noop $input(You can only convert numbers!,uwok1,Error!) }
      else {
        var %w $did(1), %x $did(3).seltext, %y $did(4).seltext
        if (%x == Fahrenheit) && (%y == Fahrenheit) { did -ra $dname 2 $iif($did(8).state == 0,%w,$round(%w,0)) }
        if (%x == Fahrenheit) && (%y == Celsius) { var %z $calc((%w -32) / 1.8)) | did -ra $dname 2 $iif($did(8).state == 0,%z,$round(%z,0)) }
        if (%x == Fahrenheit) && (%y == Kelvin) { var %z $calc(((%w - 32) / 1.8) + 273.15) | did -ra $dname 2 $iif($did(8).state == 0,%z,$round(%z,0)) }
        if (%x == Celsius) && (%y == Celsius) { did -ra $dname 2 $iif($did(8).state == 0,%w,$round(%w,0)) }
        if (%x == Celsius) && (%y == Fahrenheit) { var %z $calc((%w * 1.8) + 32)) | did -ra $dname 2 $iif($did(8).state == 0,%z,$round(%z,0)) }
        if (%x == Celsius) && (%y == Kelvin) { var %z $calc(%w + 273.15) | did -ra $dname 2 $iif($did(8).state == 0,%z,$round(%z,0)) }
        if (%x == Kelvin) && (%y == Kelvin) { did -ra $dname 2 $iif($did(8).state == 0,%w,$round(%w,0)) }
        if (%x == Kelvin) && (%y == Fahrenheit) { var %z $calc(((%w - 273.15) * 1.8 ) + 32) | did -ra $dname 2 $iif($did(8).state == 0,%z,$round(%z,0)) }
        if (%x == Kelvin) && (%y == Celsius) { var %z $calc(%w - 273.15) | did -ra $dname 2 $iif($did(8).state == 0,%z,$round(%z,0)) }
      }
      did -e $dname 6
    }
    if ($did == 6) { did -ra $dname 1-2 | did -u $dname 3-4 | did -b $dname 5-6 }
    if ($did == 7) { did -u $dname 8 | dialog -x $dname }
  }
  if ($devent == edit) && ($did == 1) && ($did(3-4).seltext) { did $iif($did(1),-e,-b) $dname 5 }
  if ($devent == close) { did -u $dname 8 }
}

Comments

Sign in to comment.
Hawkee   -  Mar 18, 2009

That's strange, I didn't do anything to change the way snippet titles are displayed. Thanks for the fix though!

 Respond  
Kirby   -  Mar 18, 2009

Oh hi there.
I think the new Hawkee's layout conflicted with it (maybe not), as the degrees symbol is an ASCII character.
Anyhow, fixed.

 Respond  
RusselB   -  Mar 18, 2009

This is weird, as the title was fine when I mad my last comment just over 2 weeks ago.

 Respond  
Hawkee   -  Mar 18, 2009

Kirby, you've got some problem characters in this snippet title. Might want to fix that.

 Respond  
RusselB   -  Mar 02, 2009

(-: Not a problem. I figured you would get back to me if you wanted/needed my assistance, and since you didn't, I wasn't worrying about it.

 Respond  
Kirby   -  Mar 02, 2009

Let me rephrase what I said:
I meant to say using too many variables in a script can often be messy and often disorganized if not properly used; and in this case, there are really no need of using variables besides the small /var's I've included.
Completely different, lol.
Yes you are right, variables can be proven to be very useful in most situations.

Also RusselB: Thanks for the pm me you sent me ages ago; I have taken that into consideration. My apologies, I haven't sent you a reply message back.

 Respond  
RusselB   -  Mar 02, 2009

Variables don't always suck, and there are times when they are invaluable.

 Respond  
Kirby   -  Nov 28, 2008

Thank you elite experts.

 Respond  
RusselB   -  Nov 27, 2008

or remove the -a switch so that you are just clearing both items.

 Respond  
guest598594   -  Nov 27, 2008

Yea, but you'd need to put another parameter in since you're using the -a switch. As long as you're clearing and writing the same thing to both of them, then yea you can do that.

 Respond  
Kirby   -  Nov 27, 2008

@napa:

Am I allowed to change:

did -ra temperature 1
did -ra temperature 2

to

did -ra temperature 1,2

?

 Respond  
Kirby   -  Nov 27, 2008

you can just combine them.

didtok temperature 3,4 32 %temperature

Yeah, I guess I can make the script slightly shorter...
I guess I should start making the rest of the temperature scales.

 Respond  
napa182   -  Nov 27, 2008

maybe add some error checks, and add the rest of the temp scales.

on this you did...

didtok temperature 3 32 %temperature
didtok temperature 4 32 %temperature

you can just combine them.

didtok temperature 3,4 32 %temperature
 Respond  
Kirby   -  Nov 24, 2008

Just not sure why I need a temp converter in Mirc? Isnt that what google is for? Other then that It looks nice.
You don't need it, but I just made it for the lulz.
Well, let's say your internet is out.
You can use the dialog to help you do the calculations.
Also, it's quicker than searching for a calculator on Google.
And, thanks. :P

 Respond  
DaDealer   -  Nov 24, 2008

Just not sure why I need a temp converter in Mirc? Isnt that what google is for? Other then that It looks nice.

 Respond  
Kirby   -  Nov 24, 2008

Don't make a god damn Temperature Converter unless you include all scales.
Rankine and Réaumur are the least commonly used and known among people, but if you prefer, I will add it later.

 Respond  
napalm`   -  Nov 24, 2008

Don't make a god damn Temperature Converter unless you include all scales.

 Respond  
napalm`   -  Nov 24, 2008

I want Rankine and Réaumur scale conversions as well.

Thanks. :)

 Respond  
Kirby   -  Nov 24, 2008

Your conversion from Farenheight to Kelvin uses the same calculation as the conversion from Kelvin to Farenheight.
Fixed.

 Respond  
RusselB   -  Nov 24, 2008

Your conversion from Farenheight to Kelvin uses the same calculation as the conversion from Kelvin to Farenheight.

 Respond  
Kirby   -  Nov 24, 2008

Use /var instead of /set, it'll make the variables local and you won't need to unset them.
Yeah, I forgot to change the /set's to /var's because I was testing to see if the commands will work.

and...

did -ra temperature 2 %temp

I'll fix that.

Thanks!

 Respond  
guest598594   -  Nov 24, 2008

Use /var instead of /set, it'll make the variables local and you won't need to unset them.

Also,

did -r temperature 2 | did -a temperature 2 %temp

You can combine switches. So you can do:

did -ra temperature 2 %temp
 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.