Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Unit Converter


  • Please log in to reply
24 replies to this topic
fuzz54
  • Members
  • 49 posts
  • Last active: Feb 23 2012 09:51 PM
  • Joined: 03 Apr 2009
Here is a fairly robust unit converter that has most common english and scientific units and most common quantities from length to density to thermal conductivity. Also includes a section for physical and mathematic constants. Conversion results can be saved to memory variables to be pasted into a simple calculator / expression evaluator.

Note: Number format and displayed decimals are modifiable now

The basic framework for this script was taken from Converter.ahk created by tidbit.

Posted Image

Posted Image

Posted Image

;; by fuzz54 http://www.autohotkey.com/forum/viewtopic.php?t=42809
; v1.3 (4-7-09) modded by Drugwash
; v1.4 (4-9-09) - Changed format/precision menu from Drugwash mod to radios and moved to bottom
;               - Changed to allow different decimals for scientific format
;               - Added units Angstrom, lightyear, parsec, and AU to distance and cm of water to pressure
;
; v1.5 (4-12-09) - Added section to list common physical constants.  made GUI wider as a result.
;                  Most of the constants are very small and show up the best in scientific format.
;                - Added an Easter egg coded by HugoV.  when To: is clicked the
;                  from and to units swap.  doesn't work with physical constants section.
;
; v1.6 (4-16-09) - Same as version 1.7, but used AHK version incompatible code for expression evaluator
;                  Expression evaluator is updated to all AHK version compatibility for 1.7
;
; v1.7 (4-16-09) - Added acres to the distance units since I hope I'll be buying a house soon
;                - Fixed the problem with 0 decimals when using scientific format
;                - Added a save-result-to-memory function for conversions with 5 memory slots
;                - Added a calculator / expression evaluator as the last choice on the conversion dropdown.
;                  There is a dropdown to paste memory variables into the expression box.
;                  The expression evaluator is taken from Laszlo's Monster code at:
;                  http://www.autohotkey.com/forum/viewtopic.php?t=17058
;                  Laszlo's code is modified slightly to work with number formatting.
;                 
; v1.8 (4-20-09) - Added section for mathematical constants
;                - Added Coefficient of Thermal Expansion to quantity list
;                - Added some more units to thermal quantities
;                - Up to 18 decimals can now be displayed instead of 9
;                - In v1.9 conversions will be updated to have 18 decimals of precision
; v1.81 (4-22-09) - Slight change to the drop down list to make it cleaner
;
; v1.9  (6-2-09) - Changed "cubic" phrase to windows character map cubed character wherever needed.
;
; v2.0  (7-6-09) - Fixed mass conversion error when using "slugs".
; v2.1  (8-7-11) - Fixed Heat Capacity conflict with Specific Heat (both have the same units which caused errors for Heat Capacity)

xe := 2.718281828459045, xpi := 3.141592653589793


;Number formatting, decimals, and groupbox dividers
Gui, Margin, -2, -2
Gui, Add, GroupBox, x-5 y-8 w298 h93 cblack,
Gui, Add, GroupBox, x-5 y-7 w298 h93 cblack,
Gui, Add, GroupBox, x-5 y78 w167 h53 cblack,
Gui, Add, GroupBox, x161 y78 w132 h53 cblack,
Gui, Add, Radio, x10 y87 h20 checked greg, Regular
Gui, Add, Radio, x10 y105 h20 gsci, Scientific
Gui, Add, Edit, x95 y102 w40 h20 gRpre vRP,
Gui, Add, UpDown, Range0-18 0x80, 2
Gui, Add, Text, x95 y87 Hide, decimals

;Memory variable controls
Gui, Add, Text, x180 y87 vgobyebye, save result to:
Gui, Add, Text, x180 y87 vgone, paste memory:
Gui, Add, DropDownList, x180 y102 w75 h17 r5 gmem vmem, Memory1|Memory2|Memory3|Memory4|Memory5
Gui, Add, DropDownList, x180 y102 w75 h17 r5 gmemrec vmemrec, Memory1|Memory2|Memory3|Memory4|Memory5

;Top GUI control - quanitity dropdown list
Gui, Add, DropDownList, x75 y4 w145 h20 r26 gunits vunits, Acceleration||Angle|Area|Coeff. of Thermal Expansion|Density|Distance|Electric Current|Energy|Force|Heat Capacity|Heat Transfer Coefficient|Mass|Power|Pressure|Specific Heat|Speed|Temperature|Thermal Conductivity|Time|Volume| |--------------------------------------------------|Physical Constants|Mathematical Constants|CALCULATOR

;Middle GUI controls, from and to units
Gui, Add, DropDownList, x6 y28 w125 h20 r30 vfrom gcalc,
Gui, Add, Text, x138 y28 w17 h20 gswap vswap +Center, To:
Gui, Add, DropDownList, x161 y28 w125 h20 r30 vto gcalc,

;Bottom GUI controls, input and result
Gui, Add, Edit, x6 y48 w125 h20 gcalc vtot,
Gui, add, updown,range1-1000 +wrap 0x80 vgoaway,1
Gui, Add, Text, x131 y48 w30 h20 +Center vequal, =
Gui, Add, Edit, x161 y48 w125 h20 vrez +readonly,

;Calculator
Gui Add, Edit, x4 y32 w165 h20 vcode Hidden,
Gui Add, Edit, x187 y32 w100 h20 vres Hidden Readonly ; no scroll bar for results
Gui Add, Button, x47 y58 w55 h20 Default Hidden vevaluate, &Evaluate
Gui Add, Button, x4 y58 w40 h20 Hidden vclear, &Clear
Gui Add, Button, x105 y58 w30 h20 Hidden vhelp, &Help
Gui, Add, Text, x175 y35 w5 h20 +Center vequals, =
Gui Add, Button, x160 y58 w16 h20 Hidden vlparen, (
Gui Add, Button, x177 y58 w16 h20 Hidden vrparen, )
Gui Add, Button, x194 y58 w16 h20 Hidden vmultiply, x
Gui Add, Button, x211 y58 w16 h20 Hidden vdivide, /
Gui Add, Button, x228 y58 w16 h20 Hidden vadd, +
Gui Add, Button, x245 y58 w16 h20 Hidden vsubtract, -
Gui Add, Button, x262 y58 w24 h20 Hidden vexponent,exp


gosub, units
gosub reg
Gui, Show, AutoSize, Unit Converter v2.1
Return

GuiClose:
ExitApp

swap:
If units=Physical Constants
   return
If units=Mathematical Constants
   return
Gui, submit, nohide
GuiControlGet, From, , Combobox4
GuiControlGet, To, , Combobox5
ControlGet, List ,List, List, Combobox4
StringReplace, List, List, `n, |, all
List .= "|"
StringReplace, FromList, List, %From%|, %From%||
StringReplace, ToList, List, %To%|, %To%||
GuiControl, , Combobox4, |
GuiControl, , Combobox4, %ToList%
GuiControl, , Combobox5, |
GuiControl, , Combobox5, %FromList%
gosub calc
Return


mem:
Gui, submit, nohide
If mem = Memory1
     Mem1=%rez%
If mem = Memory2
     Mem2=%rez%
If mem = Memory3
     Mem3=%rez%
If mem = Memory4
     Mem4=%rez%
If mem = Memory5
     Mem5=%rez%
return

memrec:
Gui, submit, nohide
If memrec = Memory1
     Pastemem=%Mem1%
If memrec = Memory2
     Pastemem=%Mem2%
If memrec = Memory3
     Pastemem=%Mem3%
If memrec = Memory4
     Pastemem=%Mem4%
If memrec = Memory5
     Pastemem=%Mem5%
coded=%code%%Pastemem%
Guicontrol,, code, %coded%
Guicontrol,focus,code
Send, {END}
gosub buttonevaluate
Return

reg:
pre = 0
If units=CALCULATOR
     gosub buttonevaluate
Else
     gosub calc
return

sci:
pre = 1
If units=CALCULATOR
     gosub buttonevaluate
Else
     gosub calc
return

Rpre:
Gui, submit, nohide
RegP = 0.%RP%
SetFormat, Float, %RegP%
If Units=CALCULATOR
     gosub buttonevaluate
Else
     gosub calc
return


ButtonClear:
   Gui Submit, Nohide
   Guicontrol,, code,
   Guicontrol,, res,
   Guicontrol,focus,code
Return

ButtonEvaluate:                                ; Alt-V or Enter: evaluate expression
   Gui Submit, NoHide
   if pre
      SetFormat, float, %RegP%E
   else
      SetFormat, float, %RegP%
   coded:=code
   GuiControl,,Res,% Eval(coded)
   Guicontrol,focus,code
   Send, {END}
return

Button(:
   Gui Submit, Nohide
   codeadd=%code%(
   Guicontrol,, code, %codeadd%
   Guicontrol,focus,code
   Send, {END}   
Return   

Button):
   Gui Submit, Nohide
   codeadd=%code%)
   Guicontrol,, code, %codeadd%
   Guicontrol,focus,code
   Send, {END}   
Return

Buttonx:
   Gui Submit, Nohide
   codeadd=%code%*
   Guicontrol,, code, %codeadd%
   Guicontrol,focus,code
   Send, {END}   
Return   

Button/:
   Gui Submit, Nohide
   codeadd=%code%/
   Guicontrol,, code, %codeadd%
   Guicontrol,focus,code
   Send, {END}   
Return

Button+:
   Gui Submit, Nohide
   codeadd=%code%+
   Guicontrol,, code, %codeadd%
   Guicontrol,focus,code
   Send, {END}   
Return

Button-:
   Gui Submit, Nohide
   codeadd=%code%-
   Guicontrol,, code, %codeadd%
   Guicontrol,focus,code
   Send, {END}
Return

ButtonExp:
   Gui Submit, Nohide
   codeadd=%code%**
   Guicontrol,, code, %codeadd%
   Guicontrol,focus,code
   Send, {END}
Return


units:
Gui, submit, nohide

if units=CALCULATOR
{
Guicontrol,focus,code
Guicontrol,Show,Code
Guicontrol,Show,Res
Guicontrol,Show,gone
Guicontrol,Show,memrec
Guicontrol,Show,Help
Guicontrol,Show,Evaluate
Guicontrol,Show,Clear
Guicontrol,Show,multiply
Guicontrol,Show,divide
Guicontrol,Show,add
Guicontrol,Show,subtract
Guicontrol,Show,exponent
Guicontrol,Show,equals
Guicontrol,Show,lparen
Guicontrol,Show,rparen
Guicontrol,Show,RP
Guicontrol,Hide,tot
Guicontrol,Hide,rez
Guicontrol,Hide,from
Guicontrol,Hide,to
Guicontrol,Hide,To:
Guicontrol,Hide,goaway
Guicontrol,Hide,gobyebye
Guicontrol,Hide,mem
Guicontrol,Hide,equal
}
else
{
Guicontrol,hide,Code
Guicontrol,hide,Res
Guicontrol,hide,gone
Guicontrol,hide,memrec
Guicontrol,hide,Help
Guicontrol,hide,Evaluate
Guicontrol,hide,Clear
Guicontrol,hide,multiply
Guicontrol,hide,divide
Guicontrol,hide,add
Guicontrol,hide,subtract
Guicontrol,hide,exponent
Guicontrol,hide,equals
Guicontrol,hide,lparen
Guicontrol,hide,rparen
Guicontrol,show,tot
Guicontrol,show,rez
Guicontrol,show,from
Guicontrol,show,to
Guicontrol,show,To:
Guicontrol,show,goaway
Guicontrol,show,gobyebye
Guicontrol,show,mem
Guicontrol,show,equal
Guicontrol,show,RP
}


if units=Mass
{
Guicontrol,, from, |
Guicontrol,, from, kilograms|grams|ounces||pounds|stone|ton|ton(uk)|slugs
Guicontrol,, to, |
Guicontrol,, to, kilograms|grams|ounces||pounds|stone|ton|ton(uk)|slugs
}

if units=Distance
{
Guicontrol,, from, |
Guicontrol,, from, feet|inches||mil|meters|centimeter|kilometer|millimeter|micron|mile|furlong|yard|Angstrom|light year|parsec|AU
Guicontrol,, to, |
Guicontrol,, to, feet|inches||mil|meters|centimeter|kilometer|millimeter|micron|mile|furlong|yard|Angstrom|light year|parsec|AU
}

if units=Density
{
Guicontrol,, from, |
Guicontrol,, from, lb/in³||lb/ft³|g/cm³|kg/m³|slugs/ft³
Guicontrol,, to, |
Guicontrol,, to, lb/in³||lb/ft³|g/cm³|kg/m³|slugs/ft³
}

if units=Acceleration
{
Guicontrol,, from, |
Guicontrol,, from, m/s²||in/s²|ft/s²|g's
Guicontrol,, to, |
Guicontrol,, to, m/s²||in/s²|ft/s²|g's
}

if units=Force
{
Guicontrol,, from, |
Guicontrol,, from, Newton||lbf|dyne
Guicontrol,, to, |
Guicontrol,, to, Newton||lbf|dyne
}

if units=Pressure
{
Guicontrol,, from, |
Guicontrol,, from, Pascal||psi|psf|torr|bar|atm|mm mercury|cm water
Guicontrol,, to, |
Guicontrol,, to, Pascal||psi|psf|torr|bar|atm|mm mercury|cm water
}

if units=Energy
{
Guicontrol,, from, |
Guicontrol,, from, Joule||BTU|in lbf|ft lbf|kcal|therm
Guicontrol,, to, |
Guicontrol,, to, Joule||BTU|in lbf|ft lbf|kcal|therm
}

if units=Power
{
Guicontrol,, from, |
Guicontrol,, from, Watt||BTU/sec|BTU/hour|hp|ft lbf/s
Guicontrol,, to, |
Guicontrol,, to, Watt||BTU/sec|BTU/hour|hp|ft lbf/s
}

if units=Time
{
Guicontrol,, from, |
Guicontrol,, from, seconds||minutes|hours|days|weeks|months(30d)|years
Guicontrol,, to, |
Guicontrol,, to, seconds||minutes|hours|days|weeks|months(30d)|years
}

if units=Thermal Conductivity
{
Guicontrol,, from, |
Guicontrol,, from, Watt/m-K||kiloWatt/m-K|BTU/hr-ft-F|BTU/hr-in-F|BTU-in/hr-ft²-F|cal/s-cm-C
Guicontrol,, to, |
Guicontrol,, to, Watt/m-K||kiloWatt/m-K|BTU/hr-ft-F|BTU/hr-in-F|BTU-in/hr-ft²-F|cal/s-cm-C
}

if units=Specific Heat
{
Guicontrol,, from, |
Guicontrol,, from, KiloJoule/kg-K||BTU/lb-F|cal/g-C
Guicontrol,, to, |
Guicontrol,, to, KiloJoule/kg-K||BTU/lb-F|cal/g-C
}

if units=Heat Capacity
{
Guicontrol,, from, |
Guicontrol,, from, J/kg-K||BTU/lb-C|BTU/lb-F|cal/g-C
Guicontrol,, to, |
Guicontrol,, to, J/kg-K||BTU/lb-C|BTU/lb-F|cal/g-C
}

if units=Heat Transfer Coefficient
{
Guicontrol,, from, |
Guicontrol,, from, Watt/m²-K||BTU/hr-ft²-F|cal/s-cm²-C|kcal/hr-ft²-C
Guicontrol,, to, |
Guicontrol,, to, Watt/m²-K||BTU/hr-ft²-F|cal/s-cm²-C|kcal/hr-ft²-C
}

if units=Area
{
Guicontrol,, from, |
Guicontrol,, from, m²||cm²|mm²|micron²|in²|ft²|yd²|mil²|acre
Guicontrol,, to, |
Guicontrol,, to, m²||cm²|mm²|micron²|in²|ft²|yd²|mil²|acre
}

if units=Volume
{
Guicontrol,, from, |
Guicontrol,, from, m³||cm³|mm³|in³|ft³|yd³|ounce|pint|quart|tsp|tbsp|liter
Guicontrol,, to, |
Guicontrol,, to, m³||cm³|mm³|in³|ft³|yd³|ounce|pint|quart|tsp|tbsp|liter
}

if units=Angle
{
Guicontrol,, from, |
Guicontrol,, from, radians||degrees|mils|minute|second|grad|cycle
Guicontrol,, to, |
Guicontrol,, to, radians||degrees|mils|minute|second|grad|cycle
}

if units=Temperature
{
Guicontrol,, from, |
Guicontrol,, from, Kelvin||Celsius|Fahrenheit|Rankine|Reaumur
Guicontrol,, to, |
Guicontrol,, to, Kelvin||Celsius|Fahrenheit|Rankine|Reaumur
}

if units=Speed
{
Guicontrol,, from, |
Guicontrol,, from, m/s||km/h|in/s|ft/s|yard/s|mph|Mach Number|speed of light
Guicontrol,, to, |
Guicontrol,, to, m/s||km/h|in/s|ft/s|yard/s|mph|Mach Number|speed of light
}

if units=Electric Current
{
Guicontrol,, from, |
Guicontrol,, from, ampere||coulomb/s|statampere
Guicontrol,, to, |
Guicontrol,, to, ampere||coulomb/s|statampere
}

if units=Physical Constants
{
Guicontrol,, from, |
Guicontrol,, from, Speed of Light (m/s)||Gravitation (m³/kg-s²)|Planck's Constant (J-s)|magnetic constant (N/A²)|electric constant (F/m)|Coulomb cons. (N-m²/C²)|elementary charge (C)|Electron Mass (kg)|Proton Mass (kg)|fine structure constant|Rydberg constant (1/m)|atomic mass unit (kg)|Avogadro's # (1/mol)|Boltzmann constant (J/K)|Faraday constant (C/mol)|gas constant (J/K-mol)|Stefan-Boltz. (W/m²-K^4)
Guicontrol,Hide, to
Guicontrol,Hide, swap
}

if units=Coeff. of Thermal Expansion
{
Guicontrol,, from, |
Guicontrol,, from, 1/°K||1/°C|1/°F|1/°R
Guicontrol,, to, |
Guicontrol,, to, 1/°K||1/°C|1/°F|1/°R
}

if units=Mathematical Constants
{
Guicontrol,, from, |
Guicontrol,, from, Pi||e|Euler-Mascheroni|Golden Ratio|Silver Ratio|Feigenbaum 1|Feigenbaum 2|Twin Prime constant|Meissel-Mertens|Laplace limit|Apéry's constant|Lévy's constant|Omega constant|Plastic Constant|Parabolic Constant|Brun's Twin Prime|Brun's Quad Prime|Khinchin's constant|Fransén-Robinson|
Guicontrol,Hide, to
Guicontrol,Hide, swap
}

gosub, calc
return

calc:
gui, submit, nohide
SetFormat, Float, 0.16E

;distance from
if from=feet
from=1.0
if from=inches
from:=.0833333
if from=mil
from:=.0000833333
if from=microns
from:=3.2808E-6
if from=meters
from=3.2808
if from=kilometer
from=3280.8399
if from=centimeter
from=0.032808399
if from=millimeter
from=0.0032808399
if from=mile
from=5280
if from=furlong
from=660
if from=yard
from=3
if from=Angstrom
from=3.280839895E-10
if from=light year
from=31017896836000000
if from=parsec
from=101236138050000000
if from=AU
from=490806662370
;distance to
if to=feet
to=1.0
if to=inches
to:=.0833333
if to=mil
to:=.0000833333
if to=micron
to:=3.2808E-6
if to=meters
to=3.2808
if to=kilometer
to=3280.8399
if to=centimeter
to=0.032808399
if to=millimeter
to=0.0032808399
if to=mile
to=5280
if to=furlong
to=660
if to=yard
to=3
if to=Angstrom
to=3.280839895E-10
if to=light year
to=31017896836000000
if to=parsec
to=101236138050000000
if to=AU
to=490806662370


;Area from
If From=m²
From=1.0
If From=cm²
From=.0001
If From=mm²
From=0.000001
If From=micron²
From=1.0E-12
If From=in²
From=0.00064516
If From=ft²
From=0.09290304
If From=yd²
From=0.83612736
If From=mil²
From=6.4516E-10
If From=acre
From=4046.8564224
;Area to
If To=m²
To=1.0
If To=cm²
To=.0001
If To=mm²
To=0.000001
If To=micron²
To=1.0E-12
If To=in²
To=0.00064516
If To=ft²
To=0.09290304
If To=yd²
To=0.83612736
If To=mil²
To=6.4516E-10
If To=acre
To=4046.8564224

;Volume from
If From=m³
From=1.0
If From=cm³
From=0.000001
If From=mm³
From=1.0E-9
If From=in³
From=0.000016387064
If From=ft³
From=0.028316846592
If From=yd³
From=0.76455485798
If From=cup
From=0.0002365882365
If From=ounce
From=0.000029573529563
If From=pint
From=0.000473176473
If From=quart
From=0.000946352946
If From=tsp
From=0.0000049289215938
If From=tbsp
From=0.000014786764781
If From=liter
From=0.001
;Volume to
If To=m³
To=1.0
If To=cm³
To=0.000001
If To=mm³
To=1.0E-9
If To=in³
To=0.000016387064
If To=ft³
To=0.028316846592
If To=yd³
To=0.76455485798
If To=cup
To=0.0002365882365
If To=ounce
To=0.000029573529563
If To=pint
To=0.000473176473
If To=quart
To=0.000946352946
If To=tsp
To=0.0000049289215938
If To=tbsp
To=0.000014786764781
If To=liter
To=0.001

;Angle from
If From=radians
From=1.0
If From=degrees
From=0.01745329252
If From=minute
From=0.00029088820867
If From=second
From=0.0000048481368111
If From=mils
From=0.00098174770425
If From=grad
From=0.015707963268
If From=cycle
From=6.2831853072
If From=circle
From=6.2831853072
;Angle to
If To=radians
To=1.0
If To=degrees
To=0.01745329252
If To=minute
To=0.00029088820867
If To=second
To=0.0000048481368111
If To=mils
To=0.00098174770425
If To=grad
To=0.015707963268
If To=cycle
To=6.2831853072
If To=circle
To=6.2831853072

;weight from
If From=Kilograms
From=2.2046226218
If From=Grams
From=0.0022046226218
If From=Ounces
From=0.0625
If From=Pounds
From=1
If From=Stone
From=14
If From=Ton
From=2000
If From=Ton(Uk)
From=2240
If From=slugs
From=32.174048695
;weight to
If To=Kilograms
To=2.2046
If To=Grams
To=0.0022046226218
If To=Ounces
To=0.0625
If To=Pounds
To=1
If To=Stone
To=14
If To=Ton
To=2000
If To=Ton(Uk)
To=2240
If To=slugs
To=32.174048695

;density from
If From=lb/in³
From=1
If From=lb/ft³
From=0.000578703
If From=Kg/m³
From=3.6127E-5
If From=slugs/ft³
From=515.31788206
If From=g/cm³
From=0.036127292927
;density to
If To=lb/in³
To=1
If To=lb/ft³
To=0.000578703
If To=Kg/m³
To=3.6127E-5
If To=slugs/ft³
To=515.31788206
If To=g/cm³
To=0.036127292927

;acceleration from
If From=m/s²
From=1
If From=in/s²
From=0.0254
If From=ft/s²
From=0.3048
If From=g's
From=9.80665
;acceleration to
If To=m/s²
To=1
If To=in/s²
To=0.0254
If To=ft/s²
To=0.3048
If To=g's
To=9.80665

;Force from
If From=Newton
From=1
If From=lbf
From=4.4482
If From=dyne
From=10.0E-6
;Force to
If To=Newton
To=1
If To=lbf
To=4.4482
If To=dyne
To=10.0E-6

;Pressure from
If From=Pascal
From=1
If From=psi
From=6894.757
If From=psf
From=47.88025
If From=torr
From=133.3224
If From=mm mercury
From=133.3224
If From=bar
From=1.0E5
If From=atm
From=101325
If From=cm water
From=98.0665
;Pressure to
If To=Pascal
To=1
If To=psi
To=6894.757
If To=psf
To=47.88025
If To=torr
To=133.3224
If To=mm mercury
To=133.3224
If To=bar
To=1.0E5
If To=atm
To=101325
If To=cm water
To=98.0665

;Energy from
If From=Joule
From=1
If From=BTU
From=1.055055E3
If From=in lbf
From=0.112984
If From=ft lbf
From=1.355817
If From=kcal
From=4186.8
If From=therm
From=105505585.257348
;Energy to
If To=Joule
To=1
If To=BTU
To=1.055055E3
If To=in lbf
To=0.112984
If To=ft lbf
To=1.355817
If To=kcal
To=4186.8
If To=therm
To=105505585.257348

;Power from
If From=Watt
From=1
If From=BTU/hour
From=0.293071
If From=BTU/sec
From=1055.055
If From=hp
From=735.49875
If From=ft lbf/s
From=1.355817
;Power to
If To=Watt
To=1
If To=BTU/hour
To=0.293071
If To=BTU/sec
To=1055.055
If To=hp
To=735.49875
If To=ft lbf/s
To=1.355817

;Time from
If From=seconds
From=1
If From=minutes
From=60
If From=hours
From=3600
If From=days
From=86400
If From=weeks
From=604800
If From=months(30d)
From=2592000
If From=years
From=31536000
;Time to
If To=seconds
To=1
If To=minutes
To=60
If To=hours
To=3600
If To=days
To=86400
If To=weeks
To=604800
If To=months(30d)
To=2592000
If To=years
To=31536000

;Thermal Conductivity from
If From=Watt/m-K
From=1
If From=kiloWatt/m-K
From=1000
If From=BTU/hr-ft-F
From=1.729577
If From=BTU/hr-in-F
From=20.754924
If From=BTU-in/hr-ft²-F
From=0.144131
If From=cal/s-cm-C
From=418.4
;Thermal Conductivity to
If To=Watt/m-K
To=1
If To=kiloWatt/m-K
To=1000
If To=BTU/hr-ft-F
To=1.729577
If To=BTU/hr-in-F
To=20.754924
If To=BTU-in/hr-ft²-F
To=0.144131
If To=cal/s-cm-C
To=418.4

;Specific Heat from
If units=Specific Heat
{
If From=KiloJoule/kg-K
From=1
If From=BTU/lb-F
From=4.1868
If From=cal/g-C
From=4.1868
;Specific Heat to
If To=KiloJoule/kg-K
To=1
If To=BTU/lb-F
To=4.1868
If To=cal/g-C
To=4.1868
}

;Heat Capacity from
If From=J/kg-K
From=1
If From=BTU/lb-C
From=2326
If From=BTU/lb-F
From=4186.8
If From=cal/g-C
From=4186.8
;Heat Capacity to
If To=J/kg-K
To=1
If To=BTU/lb-C
To=2326
If To=BTU/lb-F
To=4186.8
If To=cal/g-C
To=4186.8

;Heat Transfer Coefficient from
If From=Watt/m²-K
From=1
If From=BTU/hr-ft²-F
From=5.678263
If From=cal/s-cm²-C
From=41868
If From=kcal/hr-ft²-C
From=12.518428
;Heat Transfer Coefficient to
If To=Watt/m²-K
To=1
If To=BTU/hr-ft²-F
To=5.678263
If To=cal/s-cm²-C
To=41868
If To=kcal/hr-ft²-C
To=12.518428

;Speed from
If From=m/s
From=1
If From=km/h
From=0.277777777778
If From=in/s
From=0.0254
If From=ft/s
From=0.3048
If From=yard/s
From=0.9144
If From=mph
From=0.44704
If From=Mach Number
From=340.2933
If From=speed of light
From=299790000
;Speed to
If To=m/s
To=1
If To=km/h
To=0.277777777778
If To=in/s
To=0.0254
If To=ft/s
To=0.3048
If To=yard/s
To=0.9144
If To=mph
To=0.44704
If To=Mach Number
To=340.2933
If To=speed of light
To=299790000

;Electric Current from
If From=ampere
From=1
If From=coulomb/s
From=1
If From=statampere
From=3.335641E-10
;Electric Current to
If To=ampere
To=1
If To=coulomb/s
To=1
If To=statampere
To=3.335641E-10

;Coefficient of Thermal Expansion from
If From=1/°K
From=1.0
If From=1/°C
From=1.0
If From=1/°F
From=1.8
If From=1/°R
From=1.8
;Coefficient of Thermal Expansion to
If to=1/°K
to=1.0
If to=1/°C
to=1.0
If to=1/°F
to=1.8
If to=1/°R
to=1.8

val:=(from/to)*tot


;Temperature Equation - SPECIAL CASE
If units=Temperature
   {
   If From=Kelvin
     {
     If To=Kelvin
        val:=tot
     If To=Fahrenheit
        val:=tot*9/5-459.67
     If To=Celsius
        val:=tot-273.15
     If To=Rankine
        val:=tot*9/5
     If To=Reaumur
        val:=(tot-273.15)*4/5
     }
   Else If From=Fahrenheit
     {
     If To=Kelvin
        val:=(tot+459.67)*5/9
     If To=Fahrenheit
        val:=tot
     If To=Celsius
        val:=(tot-32)*5/9
     If To=Rankine
        val:=tot+459.67
     If To=Reaumur
        val:=(tot-32)*4/9
     }
   Else If From=Celsius
     {
     If To=Kelvin
        val:=tot+273.15
     If To=Fahrenheit
        val:=tot*9/5+32
     If To=Celsius
        val:=tot
     If To=Rankine
        val:=(tot+273.15)*9/5
     If To=Reaumur
        val:=tot*4/5
     }
   Else If From=Rankine
     {
     If To=Kelvin
        val:=tot*5/9
     If To=Fahrenheit
        val:=tot-459.67
     If To=Celsius
        val:=(tot-491.67)*5/9
     If To=Rankine
        val:=tot
     If To=Reaumur
        val:=(tot-491.67)*4/9
     }
   Else If From=Reaumur
     {
     If To=Kelvin
        val:=tot*5/4+273.15
     If To=Fahrenheit
        val:=tot*9/4+32
     If To=Celsius
        val:=tot*5/4
     If To=Rankine
        val:=tot*9/4+491.67
     If To=Reaumur
        val:=tot
     }
   }

;Physical Constants - SPECIAL CASE
If Units=Physical Constants
     {
     If From=Speed of Light (m/s)
          val:=299792458.
     If From=Gravitation (m³/kg-s²)
          val:=6.67428E-11
     If From=Planck's constant (J-s)
          val:=6.62606896E-34
     If From=magnetic constant (N/A²)
          val:=1.256637061E-6
     If From=electric constant (F/m)
          val:=8.854187817E-12
     If From=Coulomb cons. (N-m²/C²)
          val:=8.9875517873681764E9
     If From=elementary charge (C)
          val:=1.602176487E-19
     If From=Electron Mass (kg)
          val:=9.10938215E-31
     If From=Proton Mass (kg)
          val:=1.672621637E-27
     If From=fine structure constant
          val:=7.2973525376E-3
     If From=Rydberg constant (1/m)
          val:=10973731.568525
     If From=atomic mass unit (kg)
          val:=1.66053886E-27
     If From=Avogadro's # (1/mol)
          val:=6.0221415E23
     If From=Boltzmann constant (J/K)
          val:=1.3806503882381375462532721956135E-23
     If From=Faraday constant (C/mol)
          val:=96485.3371638995
     If From=gas constant (J/K-mol)
          val:=8.314472
     If From=Stefan-Boltz. (W/m²-K^4)
          val:=5.670400E-8
     }

;Mathematical Constants - SPECIAL CASE
If Units=Mathematical Constants
     {
     If From=Pi
          val:=3.14159265358979323846264338327950288
     If From=e
          val:=2.71828182845904523536028747135266249
     If From=Euler-Mascheroni
          val:=0.57721566490153286060651209008240243
     If From=Golden Ratio
          val:=1.61803398874989484820458683436563811
     If From=Silver Ratio
          val:=2.4142135623730949
     If From=Feigenbaum 1
          val:=4.66920160910299067185320382046620161
     If From=Feigenbaum 2
          val:=4.66920160910299067185320382046620161
     If From=Twin Prime constant
          val:=0.66016181584686957392781211001455577
     If From=Meissel-Mertens
          val:=0.26149721284764278375542683860869585
     If From=Laplace limit
          val:=0.66274341934918158097474209710925290
     If From=Apéry's constant
          val:=1.20205690315959428539973816151144999
     If From=Lévy's constant
          val:=3.27582291872181115978768188245384386
     If From=Omega constant
          val:= 0.56714329040978387299996866221035555
     If From=Plastic Constant
          val:=1.32471795724474602596090885447809734
     If From=Brun's Twin Prime
          val:=1.9021605823
     If From=Brun's Quad Prime
          val:=0.8705883800
     If From=Khinchin's constant
          val:=2.68545200106530644530971483548179569
     If From=Fransén-Robinson
          val:=2.80777024202851936522150118655777293
     If From=Parabolic Constant
          val:=2.29558714939263807403429804918949039
               }

if pre
   SetFormat, float, %RegP%E
else
   SetFormat, float, %RegP%
val := val + 0
guicontrol,, rez, %val%
return










;=============================================================================================================
;=============================================================================================================
;=============================================================================================================
; Expression Evaluation code by Laszlo at http://www.autohotkey.com/forum/viewtopic.php?t=17058
;
; ALL THE CODE FROM HERE AND BELOW IS ONLY FOR CALCULATOR / EXPRESSION EVALUATOR!!
;
;=============================================================================================================


SetFormat Float, 0.16e                         ; max precise AHK internal format

ButtonHelp:                                    ; Alt-H

If units=CALCULATOR
{
   MsgBox,                                     ; list of shortcuts, functions
(
Shortcut commands:
   Alt-V, Enter: evaluate expression
   Alt-c, Clear: clear calculator

Functions (AHK's and the following):

   MONSTER Version 1.1 (needs AHK 1.0.46.12+)
   EVALUATE ARITHMETIC EXPRESSIONS containing HEX, Binary ('1001), scientific numbers (1.2e+5)
   (..); variables, constants: e, pi;
   (? :); logicals ||; &&; relationals =,<>; <,>,<=,>=; user operators GCD,MIN,MAX,Choose;
   |; ^; &; <<, >>; +, -; *, /, \ (or  = mod); ** (or @ = power); !,~;
   
   Functions AHK's and Abs|Ceil|Exp|Floor|Log|Ln|Round|Sqrt|Sin|Cos|Tan|ASin|ACos|ATan|SGN|Fib|fac;
   User defined functions: f(x) := expr;

Math Constants:
   pi  = pi       e   = e

)
}
Return

Eval(x) {                              ; non-recursive PRE/POST PROCESSING: I/O forms, numbers, ops, ";"
   Local FORM, FormF, FormI, i, W, y, y1, y2, y3, y4
   FormI := A_FormatInteger, FormF := A_FormatFloat

   SetFormat Integer, D                ; decimal intermediate results!
   RegExMatch(x, "\$(b|h|x|)(\d*[eEgG]?)", y)
   FORM := y1, W := y2                 ; HeX, Bin, .{digits} output format
   SetFormat FLOAT, 0.16e              ; Full intermediate float precision
   StringReplace x, x, %y%             ; remove $..
   Loop
      If RegExMatch(x, "i)(.*)(0x[a-f\d]*)(.*)", y)
         x := y1 . y2+0 . y3           ; convert hex numbers to decimal
      Else Break
   Loop
      If RegExMatch(x, "(.*)'([01]*)(.*)", y)
         x := y1 . FromBin(y2) . y3    ; convert binary numbers to decimal: sign = first bit
      Else Break
   x := RegExReplace(x,"(^|[^.\d])(\d+)(e|E)","$1$2.$3") ; add missing '.' before E (1e3 -> 1.e3)
                                       ; literal scientific numbers between ‘ and ’ chars
   x := RegExReplace(x,"(\d*\.\d*|\d)([eE][+-]?\d+)","‘$1$2’")

   StringReplace x, x,`%, \, All       ; %  -> \ (= MOD)
   StringReplace x, x, **,@, All       ; ** -> @ for easier process
   StringReplace x, x, +, ±, All       ; ± is addition
   x := RegExReplace(x,"(‘[^’]*)±","$1+") ; ...not inside literal numbers
   StringReplace x, x, -, ¬, All       ; ¬ is subtraction
   x := RegExReplace(x,"(‘[^’]*)¬","$1-") ; ...not inside literal numbers

   Loop Parse, x, `;
      y := Eval1(A_LoopField)          ; work on pre-processed sub expressions
                                       ; return result of last sub-expression (numeric)
   If FORM = b                         ; convert output to binary
      y := W ? ToBinW(Round(y),W) : ToBin(Round(y))
   Else If (FORM="h" or FORM="x") {
      if pre
         SetFormat, float, %RegP%E
      else
         SetFormat, float, %RegP%
;      SetFormat Integer, Hex           ; convert output to hex
      y := Round(y) + 0
   }
   Else {
      W := W="" ? "0.6g" : "0." . W    ; Set output form, Default = 6 decimal places
      if pre
         SetFormat, float, %RegP%E
      else
         SetFormat, float, %RegP%
;      SetFormat FLOAT, %W%
      y += 0.0
   }
   if pre
      SetFormat, float, %RegP%E
   else
      SetFormat, float, %RegP%
;   SetFormat Integer, %FormI%          ; restore original formats
;   SetFormat FLOAT,   %FormF%
   Return y
}

Eval1(x) {                             ; recursive PREPROCESSING of :=, vars, (..) [decimal, no ";"]
   Local i, y, y1, y2, y3
                                       ; save function definition: f(x) := expr
   If RegExMatch(x, "(\S*?)\((.*?)\)\s*:=\s*(.*)", y) {
      f%y1%__X := y2, f%y1%__F := y3
      Return
   }
                                       ; execute leftmost ":=" operator of a := b := ...
   If RegExMatch(x, "(\S*?)\s*:=\s*(.*)", y) {
      y := "x" . y1                    ; user vars internally start with x to avoid name conflicts
      Return %y% := Eval1(y2)
   }
                                       ; here: no variable to the left of last ":="
   x := RegExReplace(x,"([\)’.\w]\s+|[\)’])([a-z_A-Z]+)","$1«$2»")  ; op -> «op»

   x := RegExReplace(x,"\s+")          ; remove spaces, tabs, newlines

   x := RegExReplace(x,"([a-z_A-Z]\w*)\(","'$1'(") ; func( -> 'func'( to avoid atan|tan conflicts

   x := RegExReplace(x,"([a-z_A-Z]\w*)([^\w'»’]|$)","%x$1%$2") ; VAR -> %xVAR%
   x := RegExReplace(x,"(‘[^’]*)%x[eE]%","$1e") ; in numbers %xe% -> e
   x := RegExReplace(x,"‘|’")          ; no more need for number markers
   Transform x, Deref, %x%             ; dereference all right-hand-side %var%-s

   Loop {                              ; find last innermost (..)
      If RegExMatch(x, "(.*)\(([^\(\)]*)\)(.*)", y)
         x := y1 . Eval@(y2) . y3      ; replace (x) with value of x
      Else Break
   }

   Return Eval@(x)
}

Eval@(x) {                             ; EVALUATE PRE-PROCESSED EXPRESSIONS [decimal, NO space, vars, (..), ";", ":="]
   Local i, y, y1, y2, y3, y4

   If x is number                      ; no more operators left
      Return x
                                       ; execute rightmost ?,: operator
   RegExMatch(x, "(.*)(\?|:)(.*)", y)
   IfEqual y2,?,  Return Eval@(y1) ? Eval@(y3) : ""
   IfEqual y2,:,  Return ((y := Eval@(y1)) = "" ? Eval@(y3) : y)

   StringGetPos i, x, ||, R            ; execute rightmost || operator
   IfGreaterOrEqual i,0, Return Eval@(SubStr(x,1,i)) || Eval@(SubStr(x,3+i))
   StringGetPos i, x, &&, R            ; execute rightmost && operator
   IfGreaterOrEqual i,0, Return Eval@(SubStr(x,1,i)) && Eval@(SubStr(x,3+i))
                                       ; execute rightmost =, <> operator
   RegExMatch(x, "(.*)(?<![\<\>])(\<\>|=)(.*)", y)
   IfEqual y2,=,  Return Eval@(y1) =  Eval@(y3)
   IfEqual y2,<>, Return Eval@(y1) <> Eval@(y3)
                                       ; execute rightmost <,>,<=,>= operator
   RegExMatch(x, "(.*)(?<![\<\>])(\<=?|\>=?)(?![\<\>])(.*)", y)
   IfEqual y2,<,  Return Eval@(y1) <  Eval@(y3)
   IfEqual y2,>,  Return Eval@(y1) >  Eval@(y3)
   IfEqual y2,<=, Return Eval@(y1) <= Eval@(y3)
   IfEqual y2,>=, Return Eval@(y1) >= Eval@(y3)
                                       ; execute rightmost user operator (low precedence)
   RegExMatch(x, "i)(.*)«(.*?)»(.*)", y)
   IfEqual y2,choose,Return Choose(Eval@(y1),Eval@(y3))
   IfEqual y2,Gcd,   Return GCD(   Eval@(y1),Eval@(y3))
   IfEqual y2,Min,   Return (y1:=Eval@(y1)) < (y3:=Eval@(y3)) ? y1 : y3
   IfEqual y2,Max,   Return (y1:=Eval@(y1)) > (y3:=Eval@(y3)) ? y1 : y3

   StringGetPos i, x, |, R             ; execute rightmost | operator
   IfGreaterOrEqual i,0, Return Eval@(SubStr(x,1,i)) | Eval@(SubStr(x,2+i))
   StringGetPos i, x, ^, R             ; execute rightmost ^ operator
   IfGreaterOrEqual i,0, Return Eval@(SubStr(x,1,i)) ^ Eval@(SubStr(x,2+i))
   StringGetPos i, x, &, R             ; execute rightmost & operator
   IfGreaterOrEqual i,0, Return Eval@(SubStr(x,1,i)) & Eval@(SubStr(x,2+i))
                                       ; execute rightmost <<, >> operator
   RegExMatch(x, "(.*)(\<\<|\>\>)(.*)", y)
   IfEqual y2,<<, Return Eval@(y1) << Eval@(y3)
   IfEqual y2,>>, Return Eval@(y1) >> Eval@(y3)
                                       ; execute rightmost +- (not unary) operator
   RegExMatch(x, "(.*[^!\~±¬\@\*/\\])(±|¬)(.*)", y) ; lower precedence ops already handled
   IfEqual y2,±,  Return Eval@(y1) + Eval@(y3)
   IfEqual y2,¬,  Return Eval@(y1) - Eval@(y3)
                                       ; execute rightmost */% operator
   RegExMatch(x, "(.*)(\*|/|\\)(.*)", y)
   IfEqual y2,*,  Return Eval@(y1) * Eval@(y3)
   IfEqual y2,/,  Return Eval@(y1) / Eval@(y3)
   IfEqual y2,\,  Return Mod(Eval@(y1),Eval@(y3))
                                       ; execute rightmost power
   StringGetPos i, x, @, R
   IfGreaterOrEqual i,0, Return Eval@(SubStr(x,1,i)) ** Eval@(SubStr(x,2+i))
                                       ; execute rightmost function, unary operator
   If !RegExMatch(x,"(.*)(!|±|¬|~|'(.*)')(.*)", y)
      Return x                         ; no more function (y1 <> "" only at multiple unaries: --+-)
   IfEqual y2,!,Return Eval@(y1 . !y4) ; unary !
   IfEqual y2,±,Return Eval@(y1 .  y4) ; unary +
   IfEqual y2,¬,Return Eval@(y1 . -y4) ; unary - (they behave like functions)
   IfEqual y2,~,Return Eval@(y1 . ~y4) ; unary ~
   If IsLabel(y3)
      GoTo %y3%                        ; built-in functions are executed last: y4 is number
   Return Eval@(y1 . Eval1(RegExReplace(f%y3%__F, f%y3%__X, y4))) ; user defined function
Abs:
   Return Eval@(y1 . Abs(y4))
Ceil:
   Return Eval@(y1 . Ceil(y4))
Exp:
   Return Eval@(y1 . Exp(y4))
Floor:
   Return Eval@(y1 . Floor(y4))
Log:
   Return Eval@(y1 . Log(y4))
Ln:
   Return Eval@(y1 . Ln(y4))
Round:
   Return Eval@(y1 . Round(y4))
Sqrt:
   Return Eval@(y1 . Sqrt(y4))
Sin:
   Return Eval@(y1 . Sin(y4))
Cos:
   Return Eval@(y1 . Cos(y4))
Tan:
   Return Eval@(y1 . Tan(y4))
ASin:
   Return Eval@(y1 . ASin(y4))
ACos:
   Return Eval@(y1 . ACos(y4))
ATan:
   Return Eval@(y1 . ATan(y4))
Sgn:
   Return Eval@(y1 . (y4>0)) ; Sign of x = (x>0)-(x<0)
Fib:
   Return Eval@(y1 . Fib(y4))
Fac:
   Return Eval@(y1 . Fac(y4))
}

ToBin(n) {      ; Binary representation of n. 1st bit is SIGN: -8 -> 1000, -1 -> 1, 0 -> 0, 8 -> 01000
   Return n=0||n=-1 ? -n : ToBin(n>>1) . n&1
}
ToBinW(n,W=8) { ; LS W-bits of Binary representation of n
   Loop %W%     ; Recursive (slower): Return W=1 ? n&1 : ToBinW(n>>1,W-1) . n&1
      b := n&1 . b, n >>= 1
   Return b
}
FromBin(bits) { ; Number converted from the binary "bits" string, 1st bit is SIGN
   n = 0
   Loop Parse, bits
      n += n + A_LoopField
   Return n - (SubStr(bits,1,1)<<StrLen(bits))
}

GCD(a,b) {      ; Euclidean GCD
   Return b=0 ? Abs(a) : GCD(b, mod(a,b))
}
Choose(n,k) {   ; Binomial coefficient
   p := 1, i := 0, k := k < n-k ? k : n-k
   Loop %k%                   ; Recursive (slower): Return k = 0 ? 1 : Choose(n-1,k-1)*n//k
      p *= (n-i)/(k-i), i+=1  ; FOR INTEGERS: p *= n-i, p //= ++i
   Return Round(p)
}

Fib(n) {        ; n-th Fibonacci number (n < 0 OK, iterative to avoid globals)
   a := 0, b := 1
   Loop % abs(n)-1
      c := b, b += a, a := c
   Return n=0 ? 0 : n>0 || n&1 ? b : -b
}
fac(n) {        ; n!
   Return n<2 ? 1 : n*fac(n-1)
}

Edit: v1.0 4-3-09 Grams added to weight units
Edit: v1.1 4-3-09 Temperature added. Alphabetized quantity list.
Edit: v1.2 4-7-09 Speed and Electric Current added. Some extra units added to mass and density.
Edit: v1.3 4-7-09 Modified by Drugwash to add decimal and number format menu. Thanks!
Edit: v1.4 4-9-09 Changed to put decimal and formats as radios at bottom of GUI. Added Angstrom, light year, parsec, and AU to distance. Added cm water to pressure. Scientific format can now have decimals modified too.
Edit: v1.5 4-12-09 Added a section for physical constants, and made the GUI a little wider to accomodate it. Also, an Easter egg coded by HugoV is added to swap the from and to units when the To: text is clicked on.
Edit: v1.51 4-14-09 Added option for 0 decimals back in. Only works for regular number format.
Edit: v1.6 4-16-09 Big update with many new features. Added acres to the distance units since I hope I'll be buying a house soon. Fixed the problem with 0 decimals when using scientific format. Added a save-result-to-memory function for conversions with 5 memory slots. Added a calculator / expression evaluator as the last choice on the conversion dropdown. There is a dropdown to paste memory variables into the expression box. The expression evaluator is taken from version 1.3 of Laszlo's code at: <!-- m -->http://www.autohotke...pic.php?t=26435<!-- m --> Laszlo's code is modified to have many bells and whistles stripped out. It is modified in some places to work with the unit converter script.
Edit: v1.7 4-16-09 Same as version 1.6, but the expression evaluation code has been changed to use the Monster evaluator by Laszlo at <!-- m -->http://www.autohotke...pic.php?t=17058<!-- m -->
This expression evaluator is for the most part independent of AHK version. Thanks Laszlo!
Edit: v1.8 4-20-09 Added a section for mathematical constants. Added Coefficient of Thermal Expansion. Added some more units to some of the thermal quantities. Up to 18 decimals can now be displayed instead of 9.
Edit: v1.81 4-22-09 Changed the drop down list to make it a little cleaner.
Edit: v2.0 7-6-09 Changed cubic phrase to windows character map "cubed" character. Fixed error in mass conversion when using slugs.
Edit: v2.1 8-7-11 Fixed Heat Capacity conflict with Specific Heat (both have the same units)

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
I only played with it for like 45 seconds, but noticed right away...

Does the result always have to be in scientific notation?
Seems a little over-the-top for 60 seconds to equal 1.0000E+000 minutes.

Otherwise, this could prove quite useful.

Thanks -

[edit] No temperature conversions? Celsius to Fahrenheit to Kelvin to Rankine to Reaumur?

fuzz54
  • Members
  • 49 posts
  • Last active: Feb 23 2012 09:51 PM
  • Joined: 03 Apr 2009

Only played with it for like 45 seconds, but noticed right away...
Does the result always have to be in scientific notation?
Seems a little over-the-top for 60 seconds to equal 1.0000E+000 minutes.

Otherwise, this could prove quite useful.

Thanks -


If you want this in normal number formatting then try changing the first line to SetFormat, float, 0.4. You might even change the 0.4 to 0.2 if you don't care that much about getting out to 4 decimal places.

I messed around with trying to add a couple radio buttons for scientific or normal number formatting by messing with SetFormat (top of script) but it wasn't working. Maybe SetFormat can't be changed in a script once it is set, but I have a feeling it was just lack of programming skill on my part. I also wanted to add a button for number of decimal places displayed, but couldn't figure out an easy way to do that.

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
All-in-all, great effort!
I like it.

Note: While you were replying, I edited my post...
No temperature conversions?

fuzz54
  • Members
  • 49 posts
  • Last active: Feb 23 2012 09:51 PM
  • Joined: 03 Apr 2009

[edit] No temperature conversions? Celsius to Fahrenheit to Kelvin to Rankine to Reaumur?


Temperature would have to be done in some other way since it doesn't use ratios and needs an addition or subtraction operator. It'd be easy to do with an IF statement at the bottom for a special form of "val" variable just for temperatures.

I'll add temperature to it soon since I agree that it would be useful.

jmanx
  • Members
  • 110 posts
  • Last active: Mar 20 2011 07:55 PM
  • Joined: 14 May 2008

Grams and temp would be nice new features if you know how to



fuzz54
  • Members
  • 49 posts
  • Last active: Feb 23 2012 09:51 PM
  • Joined: 03 Apr 2009

Grams and temp would be nice new features if you know how to


Grams has been added to the script.

tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
hehe, nice improvement ^^ maybe I'll take it.

edit:
I could probably do the temperature system for you. Will try it later.

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


fuzz54
  • Members
  • 49 posts
  • Last active: Feb 23 2012 09:51 PM
  • Joined: 03 Apr 2009

hehe, nice improvement ^^ maybe I'll take it.

edit:
I could probably do the temperature system for you. Will try it later.


Thanks tidbit. I just added temperature. There could be an error with that since it requires a 5x5 matrix instead of ratios, but I think I got it with 5 nested If statements. I also alphabetized the quantities to be converted since that seemed less annoying.

fuzz54
  • Members
  • 49 posts
  • Last active: Feb 23 2012 09:51 PM
  • Joined: 03 Apr 2009
For anyone that cares, I added speed and electric current to the unit converter. That probably covers everything that most people would need to convert, so this will be the last revision unless I'm wrong.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Cool! It often comes very handy.

I missed under pressure "cm Water".
- under distance: Ångström, light-year, parsec

Adding links to the corresponding Wikipedia page would make the definitions also easily accessible.

You could have separate controls for the decimal modifiers, like deci, centi, milli... and deka, hecto, kilo...

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
A small enhancement to the script. Could be done differently, of course, so feel free to change it if you want.

; by fuzz54 http://www.autohotkey.com/forum/viewtopic.php?t=42809
; v1.3 (4-7-09) modded by Drugwash

Menu, opt, Add, &Regular, reg
Menu, opt, Add, &Scientific, sci
Menu, ConvMenu, Add, &Precision, :opt
Gui, Menu, ConvMenu
Gui, Add, Edit, x6 y4 w30 h20 gRpre vRP Hidden,
Gui, Add, UpDown, Range0-8 -wrap 0x80, 1
Gui, Add, Text, x+1 yp+3 Hide, decimals
Gui, Add, DropDownList, x86 y4 w150 h20 r19 gunits vunits, Acceleration||Angle|Area|Density|Distance|Electric Current|Energy|Force|Heat Capacity|Heat Transfer Coefficient|Mass|Power|Pressure|Specific Heat|Speed|Temperature|Thermal Conductivity|Time|Volume|


Gui, Add, DropDownList, x6 y28 w100 h20 r13 vfrom gcalc,
Gui, Add, Text, x106 y28 w30 h20 +Center, To:
Gui, Add, DropDownList, x136 y28 w100 h20 r13 vto gcalc,

Gui, Add, Edit, x6 y48 w100 h20 gcalc vtot,
Gui, add, updown,range1-5500 +wrap 0x80,1
Gui, Add, Text, x106 y48 w30 h20 +Center, =
Gui, Add, Edit, x136 y48 w100 h20 vres +readonly,

gosub, units
gosub sci
Gui, Show, , Unit Converter
Return

reg:
Menu, opt, Uncheck, &Scientific
Menu, opt, Check, &Regular
GuiControl, Show, RP
GuiControl, Show, msctls_updown321
GuiControl, Show, Static1
pre = 0
gosub calc
return

sci:
Menu, opt, Uncheck, &Regular
Menu, opt, Check, &Scientific
GuiControl, Hide, RP
GuiControl, Hide, msctls_updown321
GuiControl, Hide, Static1
pre = 1
gosub calc
return

Rpre:
Gui, submit, nohide
SetFormat, Float, 0.1
RegP := RP/10
SetFormat, Float, %RegP%
gosub calc
return

units:
Gui, submit, nohide
if units=Mass
{
Guicontrol,, from, |
Guicontrol,, from, kilograms|grams|ounces||pounds|stone|ton|ton(uk)|slugs
Guicontrol,, to, |
Guicontrol,, to, kilograms|grams|ounces||pounds|stone|ton|ton(uk)|slugs
}

if units=Distance
{
Guicontrol,, from, |
Guicontrol,, from, feet|inches||mil|meters|centimeter|kilometer|millimeter|micron|mile|furlong|yard
Guicontrol,, to, |
Guicontrol,, to, feet|inches||mil|meters|centimeter|kilometer|millimeter|micron|mile|furlong|yard
}

if units=Density
{
Guicontrol,, from, |
Guicontrol,, from, lb/cubic inch||lb/cubic foot|kg/cubic meter|slugs/cubic foot
Guicontrol,, to, |
Guicontrol,, to, lb/cubic inch||lb/cubic foot|kg/cubic meter|slugs/cubic foot
}

if units=Acceleration
{
Guicontrol,, from, |
Guicontrol,, from, m/s2||in/s2|ft/s2|g's
Guicontrol,, to, |
Guicontrol,, to, m/s2||in/s2|ft/s2|g's
}

if units=Force
{
Guicontrol,, from, |
Guicontrol,, from, Newton||lbf|dyne
Guicontrol,, to, |
Guicontrol,, to, Newton||lbf|dyne
}

if units=Pressure
{
Guicontrol,, from, |
Guicontrol,, from, Pascal||psi|psf|torr|mm mercury|bar|atm
Guicontrol,, to, |
Guicontrol,, to, Pascal||psi|psf|torr|mm mercury|bar|atm
}

if units=Energy
{
Guicontrol,, from, |
Guicontrol,, from, Joule||BTU|in lbf|ft lbf|kcal|therm
Guicontrol,, to, |
Guicontrol,, to, Joule||BTU|in lbf|ft lbf|kcal|therm
}

if units=Power
{
Guicontrol,, from, |
Guicontrol,, from, Watt||BTU/sec|BTU/hour|hp|ft lbf/s
Guicontrol,, to, |
Guicontrol,, to, Watt||BTU/sec|BTU/hour|hp|ft lbf/s
}

if units=Time
{
Guicontrol,, from, |
Guicontrol,, from, seconds||minutes|hours|days|weeks|months(30d)|years
Guicontrol,, to, |
Guicontrol,, to, seconds||minutes|hours|days|weeks|months(30d)|years
}

if units=Thermal Conductivity
{
Guicontrol,, from, |
Guicontrol,, from, Watt/m-K||kiloWatt/m-K|BTU/hr-ft-F|BTU-in/hr-ft2-F|cal/s-cm-C
Guicontrol,, to, |
Guicontrol,, to, Watt/m-K||kiloWatt/m-K|BTU/hr-ft-F|BTU-in/hr-ft2-F|cal/s-cm-C
}

if units=Specific Heat
{
Guicontrol,, from, |
Guicontrol,, from, KiloJoule/kg-K||BTU/lb-F|cal/g-C
Guicontrol,, to, |
Guicontrol,, to, KiloJoule/kg-K||BTU/lb-F|cal/g-C
}

if units=Heat Capacity
{
Guicontrol,, from, |
Guicontrol,, from, J/kg-K||BTU/lb-C|BTU/lb-F|cal/g-C
Guicontrol,, to, |
Guicontrol,, to, J/kg-K||BTU/lb-C|BTU/lb-F|cal/g-C
}

if units=Heat Transfer Coefficient
{
Guicontrol,, from, |
Guicontrol,, from, Watt/m2-K||BTU/hr-ft2-F|cal/s-cm2-C|kcal/hr-ft2-C
Guicontrol,, to, |
Guicontrol,, to, Watt/m2-K||BTU/hr-ft2-F|cal/s-cm2-C|kcal/hr-ft2-C
}

if units=Area
{
Guicontrol,, from, |
Guicontrol,, from, m2||cm2|mm2|micron2|in2|ft2|yd2|mil2
Guicontrol,, to, |
Guicontrol,, to, m2||cm2|mm2|micron2|in2|ft2|yd2|mil2
}

if units=Volume
{
Guicontrol,, from, |
Guicontrol,, from, cubic meters||cubic centimeters|cubic millimeters|cubic inches|cubic feet|cubic yards|ounce|pint|quart|tsp|tbsp|liter
Guicontrol,, to, |
Guicontrol,, to, cubic meters||cubic centimeters|cubic millimeters|cubic inches|cubic feet|cubic yards|ounce|pint|quart|tsp|tbsp|liter
}

if units=Angle
{
Guicontrol,, from, |
Guicontrol,, from, radians||degrees|mils|minute|second|grad|cycle
Guicontrol,, to, |
Guicontrol,, to, radians||degrees|mils|minute|second|grad|cycle
}

if units=Temperature
{
Guicontrol,, from, |
Guicontrol,, from, Kelvin||Celsius|Fahrenheit|Rankine|Reaumur
Guicontrol,, to, |
Guicontrol,, to, Kelvin||Celsius|Fahrenheit|Rankine|Reaumur
}

if units=Speed
{
Guicontrol,, from, |
Guicontrol,, from, m/s||km/h|in/s|ft/s|yard/s|mph|Mach Number|speed of light
Guicontrol,, to, |
Guicontrol,, to, m/s||km/h|in/s|ft/s|yard/s|mph|Mach Number|speed of light
}

if units=Electric Current
{
Guicontrol,, from, |
Guicontrol,, from, ampere||coulomb/s|statampere
Guicontrol,, to, |
Guicontrol,, to, ampere||coulomb/s|statampere
}

gosub, calc
return

calc:
gui, submit, nohide

;distance from
if from=feet
from=1.0
if from=inches
from:=.0833333
if from=mil
from:=.0000833333
if from=microns
from:=3.2808E-6
if from=meters
from=3.2808
if from=kilometer
from=3280.8399
if from=centimeter
from=0.032808399
if from=millimeter
from=0.0032808399
if from=mile
from=5280
if from=furlong
from=660
if from=yard
from=3
;distance to
if to=feet
to=1.0
if to=inches
to:=.0833333
if to=mil
to:=.0000833333
if to=micron
to:=3.2808E-6
if to=meters
to=3.2808
if to=kilometer
to=3280.8399
if to=centimeter
to=0.032808399
if to=millimeter
to=0.0032808399
if to=mile
to=5280
if to=furlong
to=660
if to=yard
to=3

;Area from
If From=m2
From=1.0
If From=cm2
From=.0001
If From=mm2
From=0.000001
If From=micron2
From=1.0E-12
If From=in2
From=0.00064516
If From=ft2
From=0.09290304
If From=yd2
From=0.83612736
If From=mil2
From=6.4516E-10
;Area to
If To=m2
To=1.0
If To=cm2
To=.0001
If To=mm2
To=0.000001
If To=micron2
To=1.0E-12
If To=in2
To=0.00064516
If To=ft2
To=0.09290304
If To=yd2
To=0.83612736
If To=mil2
To=6.4516E-10

;Volume from
If From=cubic meters
From=1.0
If From=cubic centimeters
From=0.000001
If From=cubic millimeters
From=1.0E-9
If From=cubic inches
From=0.000016387064
If From=cubic feet
From=0.028316846592
If From=cubic yards
From=0.76455485798
If From=cup
From=0.0002365882365
If From=ounce
From=0.000029573529563
If From=pint
From=0.000473176473
If From=quart
From=0.000946352946
If From=tsp
From=0.0000049289215938
If From=tbsp
From=0.000014786764781
If From=liter
From=0.001
;Volume to
If To=cubic meters
To=1.0
If To=cubic centimeters
To=0.000001
If To=cubic millimeters
To=1.0E-9
If To=cubic inches
To=0.000016387064
If To=cubic feet
To=0.028316846592
If To=cubic yards
To=0.76455485798
If To=cup
To=0.0002365882365
If To=ounce
To=0.000029573529563
If To=pint
To=0.000473176473
If To=quart
To=0.000946352946
If To=tsp
To=0.0000049289215938
If To=tbsp
To=0.000014786764781
If To=liter
To=0.001

;Angle from
If From=radians
From=1.0
If From=degrees
From=0.01745329252
If From=minute
From=0.00029088820867
If From=second
From=0.0000048481368111
If From=mils
From=0.00098174770425
If From=grad
From=0.015707963268
If From=cycle
From=6.2831853072
If From=circle
From=6.2831853072
;Angle to
If To=radians
To=1.0
If To=degrees
To=0.01745329252
If To=minute
To=0.00029088820867
If To=second
To=0.0000048481368111
If To=mils
To=0.00098174770425
If To=grad
To=0.015707963268
If To=cycle
To=6.2831853072
If To=circle
To=6.2831853072

;weight from
If From=Kilograms
From=2.2046226218
If From=Grams
From=0.0022046226218
If From=Ounces
From=0.0625
If From=Pounds
From=1
If From=Stone
From=14
If From=Ton
From=2000
If From=Ton (Uk)
From=2240
If From=slugs
From=14.593903
;weight to
If To=Kilograms
To=2.2046
If To=Grams
To=0.0022046226218
If To=Ounces
To=0.0625
If To=Pounds
To=1
If To=Stone
To=14
If To=Ton
To=2000
If To=Ton (Uk)
To=2240
If To=slugs
To=14.593903

;density from
If From=lb/cubic inch
From=1
If From=lb/cubic foot
From=0.000578703
If From=Kg/cubic meter
From=3.6127E-5
If From=slugs/cubic foot
From=515.31788206
;density to
If To=lb/cubic inch
To=1
If To=lb/cubic foot
To=0.000578703
If To=Kg/cubic meter
To=3.6127E-5
If To=slugs/cubic foot
To=515.31788206

;acceleration from
If From=m/s2
From=1
If From=in/s2
From=0.0254
If From=ft/s2
From=0.3048
If From=g's
From=9.80665
;acceleration to
If To=m/s2
To=1
If To=in/s2
To=0.0254
If To=ft/s2
To=0.3048
If To=g's
To=9.80665

;Force from
If From=Newton
From=1
If From=lbf
From=4.4482
If From=dyne
From=10.0E-6
;Force to
If To=Newton
To=1
If To=lbf
To=4.4482
If To=dyne
To=10.0E-6

;Pressure from
If From=Pascal
From=1
If From=psi
From=6894.757
If From=psf
From=47.88025
If From=torr
From=133.3224
If From=mm mercury
From=133.3224
If From=bar
From=1.0E5
If From=atm
From=101325
;Pressure to
If To=Pascal
To=1
If To=psi
To=6894.757
If To=psf
To=47.88025
If To=torr
To=133.3224
If To=mm mercury
To=133.3224
If To=bar
To=1.0E5
If To=atm
To=101325

;Energy from
If From=Joule
From=1
If From=BTU
From=1.055055E3
If From=in lbf
From=0.112984
If From=ft lbf
From=1.355817
If From=kcal
From=4186.8
If From=therm
From=105505585.257348
;Energy to
If To=Joule
To=1
If To=BTU
To=1.055055E3
If To=in lbf
To=0.112984
If To=ft lbf
To=1.355817
If To=kcal
To=4186.8
If To=therm
To=105505585.257348

;Power from
If From=Watt
From=1
If From=BTU/hour
From=0.293071
If From=BTU/sec
From=1055.055
If From=hp
From=735.49875
If From=ft lbf/s
From=1.355817
;Power to
If To=Watt
To=1
If To=BTU/hour
To=0.293071
If To=BTU/sec
To=1055.055
If To=hp
To=735.49875
If To=ft lbf/s
To=1.355817

;Time from
If From=seconds
From=1
If From=minutes
From=60
If From=hours
From=3600
If From=days
From=86400
If From=weeks
From=604800
If From=months(30d)
From=2592000
If From=years
From=31536000
;Time to
If To=seconds
To=1
If To=minutes
To=60
If To=hours
To=3600
If To=days
To=86400
If To=weeks
To=604800
If To=months(30d)
To=2592000
If To=years
To=31536000

;Thermal Conductivity from
If From=Watt/m-K
From=1
If From=kiloWatt/m-K
From=1000
If From=BTU/hr-ft-F
From=1.729577
If From=BTU-in/hr-ft2-F
From=0.144131
If From=cal/s-cm-C
From=418.4
;Thermal Conductivity to
If To=Watt/m-K
To=1
If To=kiloWatt/m-K
To=1000
If To=BTU/hr-ft-F
To=1.729577
If To=BTU-in/hr-ft2-F
To=0.144131
If To=cal/s-cm-C
To=418.4

;Specific Heat from
If From=KiloJoule/kg-K
From=1
If From=BTU/lb-F
From=4.1868
If From=cal/g-C
From=4.1868
;Specific Heat to
If To=KiloJoule/kg-K
To=1
If To=BTU/lb-F
To=4.1868
If To=cal/g-C
To=4.1868

;Heat Capacity from
If From=J/kg-K
From=1
If From=BTU/lb-C
From=2326
If From=BTU/lb-F
From=4186.8
If From=cal/g-C
From=4186.8
;Heat Capacity to
If To=J/kg-K
To=1
If To=BTU/lb-C
To=2326
If To=BTU/lb-F
To=4186.8
If To=cal/g-C
To=4186.8

;Heat Transfer Coefficient from
If From=Watt/m2-K
From=1
If From=BTU/hr-ft2-F
From=5.678263
If From=cal/s-cm2-C
From=41868
If From=kcal/hr-ft2-C
From=12.518428
;Heat Transfer Coefficient to
If To=Watt/m2-K
To=1
If To=BTU/hr-ft2-F
To=5.678263
If To=cal/s-cm2-C
To=41868
If To=kcal/hr-ft2-C
To=12.518428

;Speed from
If From=m/s
From=1
If From=km/h
From=0.277777777778
If From=in/s
From=0.0254
If From=ft/s
From=0.3048
If From=yard/s
From=0.9144
If From=mph
From=0.44704
If From=Mach Number
From=340.2933
If From=speed of light
From=299790000
;Speed to
If To=m/s
To=1
If To=km/h
To=0.277777777778
If To=in/s
To=0.0254
If To=ft/s
To=0.3048
If To=yard/s
To=0.9144
If To=mph
To=0.44704
If To=Mach Number
To=340.2933
If To=speed of light
To=299790000

;Electric Current from
If From=ampere
From=1
If From=coulomb/s
From=1
If From=statampere
From=3.335641E-10
;Electric Current to
If To=ampere
To=1
If To=coulomb/s
To=1
If To=statampere
To=3.335641E-10

val:=(from/to)*tot

;Temperature Equation - SPECIAL CASE
If units=Temperature
   {
   If From=Kelvin
     {
     If To=Kelvin
        val:=tot
     If To=Fahrenheit
        val:=tot*9/5-459.67
     If To=Celsius
        val:=tot-273.15
     If To=Rankine
        val:=tot*9/5
     If To=Reaumur
        val:=(tot-273.15)*4/5
     }
   Else If From=Fahrenheit
     {
     If To=Kelvin
        val:=(tot+459.67)*5/9
     If To=Fahrenheit
        val:=tot
     If To=Celsius
        val:=(tot-32)*5/9
     If To=Rankine
        val:=tot+459.67
     If To=Reaumur
        val:=(tot-32)*4/9
     }
   Else If From=Celsius
     {
     If To=Kelvin
        val:=tot+273.15
     If To=Fahrenheit
        val:=tot*9/5+32
     If To=Celsius
        val:=tot
     If To=Rankine
        val:=(tot+273.15)*9/5
     If To=Reaumur
        val:=tot*4/5
     }
   Else If From=Rankine
     {
     If To=Kelvin
        val:=tot*5/9
     If To=Fahrenheit
        val:=tot-459.67
     If To=Celsius
        val:=(tot-491.67)*5/9
     If To=Rankine
        val:=tot
     If To=Reaumur
        val:=(tot-491.67)*4/9
     }
   Else If From=Reaumur
     {
     If To=Kelvin
        val:=tot*5/4+273.15
     If To=Fahrenheit
        val:=tot*9/4+32
     If To=Celsius
        val:=tot*5/4
     If To=Rankine
        val:=tot*9/4+491.67
     If To=Reaumur
        val:=tot
     }
   }
if pre
	SetFormat, floatfast, 0.4E
else
	SetFormat, floatfast, %RegP%
val := val + 0
guicontrol,, res, %val%
return

GuiClose:
ExitApp


fuzz54
  • Members
  • 49 posts
  • Last active: Feb 23 2012 09:51 PM
  • Joined: 03 Apr 2009

A small enhancement to the script. Could be done differently, of course, so feel free to change it if you want.


It couldn't have been done differently by me since you have more autohotkey knowledge than I do. I never would have figured it out without this example. And thanks for that, because it also solves problems I was having with setting number format in a similar material property script I'm writing.

I'll update the code at top of post later today to use your enhancements. I might tweak a couple things, but it'll look pretty much the same. Also, I changed "floatfast" at the bottom to be "float" since that was giving me problems in getting the script to run. It works fine after that.

Again, Thanks!

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
You're welcome, glad to be of help! ;)

As for FloatFast, it's been introduced with AHK 1.0.48 and you're probably running an older version, that's why it wouldn't work for you; no problem though, it should run fine with Float as well.

fuzz54
  • Members
  • 49 posts
  • Last active: Feb 23 2012 09:51 PM
  • Joined: 03 Apr 2009
The script now has Angstrom, light year, parsec, and AU added to length and cm water added to pressure.

I changed the mod from Drugwash to use radio buttons instead of menu for number format. Number of decimals is now always visible and allows both regular and scientific formats to change # of decimals. Just my personal preference.