Posted By

Scooter on 03/12/08


Tagged

conversion temperature unit


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

asifrizvigmailcom


Temperature Conversion


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com

This function library allows conversion between temperatures in the following scales: Celsius, Delisle, Fahrenheit, Kelvin, Newton, Rankine, Reaumur, and Romer.

  1. <%
  2. ' ASP Temperature Conversion Library
  3. '
  4. ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
  5. '
  6. ' This work is licensed under the Creative Commons Attribution License. To view
  7. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  8. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  9. ' 94305, USA.
  10. '
  11. ' This function library allows conversion between temperatures in the following scales:
  12. ' Celsius, Delisle, Fahrenheit, Kelvin, Newton, Rankine, Reaumur, and Romer.
  13. '
  14. ' Refer to Wikipedia for information on these temperature scales.
  15.  
  16. ' Facade function, in case you'd rather not call the individual functions directly or you just like encapsulation.
  17. function convertTemperature(temperature, originScale, targetScale)
  18. ' Return the input value for temperature if both scales are identical.
  19. if UCASE(originScale) = UCase(targetScale) then
  20. convertTemperature = temperature
  21. exit function
  22. end if
  23.  
  24. Select Case UCase(originScale)
  25. Case "CELSIUS"
  26. Select Case UCase(targetScale)
  27. Case "DELISLE"
  28. convertTemperature = CelsiusToDelisle(temperature)
  29. Case "FAHRENHEIT"
  30. convertTemperature = CelsiusToFahrenheit(temperature)
  31. Case "KELVIN"
  32. convertTemperature = CelsiusToKelvin(temperature)
  33. Case "NEWTON"
  34. convertTemperature = CelsiusToNewton(temperature)
  35. Case "RANKINE"
  36. convertTemperature = CelsiusToRankine(temperature)
  37. Case "REAUMUR"
  38. convertTemperature = CelsiusToReaumur(temperature)
  39. Case "ROMER"
  40. convertTemperature = CelsiusToRomer(temperature)
  41. End Select
  42. Case "DELISLE"
  43. Select Case UCase(targetScale)
  44. Case "CELSIUS"
  45. convertTemperature = DelisleToCelsius(temperature)
  46. Case "FAHRENHEIT"
  47. convertTemperature = DelisleToFahrenheit(temperature)
  48. Case "KELVIN"
  49. convertTemperature = DelisleToKelvin(temperature)
  50. Case "NEWTON"
  51. convertTemperature = DelisleToNewton(temperature)
  52. Case "RANKINE"
  53. convertTemperature = DelisleToRankine(temperature)
  54. Case "REAUMUR"
  55. convertTemperature = DelisleToReaumur(temperature)
  56. Case "ROMER"
  57. convertTemperature = DelisleToRomer(temperature)
  58. End Select
  59. Case "FAHRENHEIT"
  60. Select Case UCase(targetScale)
  61. Case "CELSIUS"
  62. convertTemperature = FahrenheitToCelsius(temperature)
  63. Case "DELISLE"
  64. convertTemperature = FahrenheitToDelisle(temperature)
  65. Case "KELVIN"
  66. convertTemperature = FahrenheitToKelvin(temperature)
  67. Case "NEWTON"
  68. convertTemperature = FahrenheitToNewton(temperature)
  69. Case "RANKINE"
  70. convertTemperature = FahrenheitToRankine(temperature)
  71. Case "REAUMUR"
  72. convertTemperature = FahrenheitToReaumur(temperature)
  73. Case "ROMER"
  74. convertTemperature = FahrenheitToRomer(temperature)
  75. End Select
  76. Case "KELVIN"
  77. Select Case UCase(targetScale)
  78. Case "CELSIUS"
  79. convertTemperature = KelvinToCelsius(temperature)
  80. Case "DELISLE"
  81. convertTemperature = KelvinToDelisle(temperature)
  82. Case "FAHRENHEIT"
  83. convertTemperature = KelvinToFahrenheit(temperature)
  84. Case "NEWTON"
  85. convertTemperature = KelvinToNewton(temperature)
  86. Case "RANKINE"
  87. convertTemperature = KelvinToRankine(temperature)
  88. Case "REAUMUR"
  89. convertTemperature = KelvinToReaumur(temperature)
  90. Case "ROMER"
  91. convertTemperature = KelvinToRomer(temperature)
  92. End Select
  93. Case "NEWTON"
  94. Select Case UCase(targetScale)
  95. Case "CELSIUS"
  96. convertTemperature = NewtonToCelsius(temperature)
  97. Case "DELISLE"
  98. convertTemperature = NewtonToDelisle(temperature)
  99. Case "FAHRENHEIT"
  100. convertTemperature = NewtonToFahrenheit(temperature)
  101. Case "KELVIN"
  102. convertTemperature = NewtonToKelvin(temperature)
  103. Case "RANKINE"
  104. convertTemperature = NewtonToRankine(temperature)
  105. Case "REAUMUR"
  106. convertTemperature = NewtonToReaumur(temperature)
  107. Case "ROMER"
  108. convertTemperature = NewtonToRomer(temperature)
  109. End Select
  110. Case "RANKINE"
  111. Select Case UCase(targetScale)
  112. Case "CELSIUS"
  113. convertTemperature = RankineToCelsius(temperature)
  114. Case "DELISLE"
  115. convertTemperature = RankineToDelisle(temperature)
  116. Case "FAHRENHEIT"
  117. convertTemperature = RankineToFahrenheit(temperature)
  118. Case "KELVIN"
  119. convertTemperature = RankineToKelvin(temperature)
  120. Case "NEWTON"
  121. convertTemperature = RankineToNewton(temperature)
  122. Case "REAUMUR"
  123. convertTemperature = RankineToReaumur(temperature)
  124. Case "ROMER"
  125. convertTemperature = RankineToRomer(temperature)
  126. End Select
  127. Case "REAUMUR"
  128. Select Case UCase(targetScale)
  129. Case "CELSIUS"
  130. convertTemperature = ReaumurToCelsius(temperature)
  131. Case "DELISLE"
  132. convertTemperature = ReaumurToDelisle(temperature)
  133. Case "FAHRENHEIT"
  134. convertTemperature = ReaumurToFahrenheit(temperature)
  135. Case "KELVIN"
  136. convertTemperature = ReaumurToKelvin(temperature)
  137. Case "NEWTON"
  138. convertTemperature = ReaumurToNewton(temperature)
  139. Case "RANKINE"
  140. convertTemperature = ReaumurToRankine(temperature)
  141. Case "ROMER"
  142. convertTemperature = ReaumurToRomer(temperature)
  143. End Select
  144. Case "ROMER"
  145. Select Case UCase(targetScale)
  146. Case "CELSIUS"
  147. convertTemperature = RomerToCelsius(temperature)
  148. Case "DELISLE"
  149. convertTemperature = RomerToDelisle(temperature)
  150. Case "FAHRENHEIT"
  151. convertTemperature = RomerToFahrenheit(temperature)
  152. Case "KELVIN"
  153. convertTemperature = RomerToKelvin(temperature)
  154. Case "NEWTON"
  155. convertTemperature = RomerToNewton(temperature)
  156. Case "RANKINE"
  157. convertTemperature = RomerToRankine(temperature)
  158. Case "REAUMUR"
  159. convertTemperature = RomerToReaumur(temperature)
  160. End Select
  161. End Select
  162. end function
  163.  
  164. ' Converts a given temperature from Celsius to Delisle.
  165. function CelsiusToDelisle(temperature)
  166. CelsiusToDelisle = (100 - temperature) * 3 / 2
  167. end function
  168.  
  169. ' Converts a given temperature from Celsius to Fahrenheit.
  170. function CelsiusToFahrenheit(temperature)
  171. CelsiusToFahrenheit = (temperature * 9 / 5) + 32
  172. end function
  173.  
  174. ' Converts a given temperature from Celsius to Kelvin.
  175. function CelsiusToKelvin(temperature)
  176. CelsiusToKelvin = temperature + 273.15
  177. end function
  178.  
  179. ' Converts a given temperature from Celsius to Newton.
  180. function CelsiusToNewton(temperature)
  181. CelsiusToNewton = temperature * 33 / 100
  182. end function
  183.  
  184. ' Converts a given temperature from Celsius to Rankine.
  185. function CelsiusToRankine(temperature)
  186. CelsiusToRankine = (temperature + 273.15) * 1.8
  187. end function
  188.  
  189. ' Converts a given temperature from Celsius to Reaumur.
  190. function CelsiusToReaumur(temperature)
  191. CelsiusToReamur = temperature * 4 / 5
  192. end function
  193.  
  194. ' Converts a given temperature from Celsius to Romer.
  195. function CelsiusToRomer(temperature)
  196. CelsiusToRomer = temperature * 21 / 40 + 7.5
  197. end function
  198.  
  199. ' Converts a given temperature from Delisle to Celsius.
  200. function DelisleToCelsius(temperature)
  201. DelisleToCelsius = 100 - temperature * 2 / 3
  202. end function
  203.  
  204. ' Converts a given temperature from Delisle to Fahrenheit.
  205. function DelisleToFahrenheit(temperature)
  206. DelisleToFahrenheit = 212 - temperature * 6 / 5
  207. end function
  208.  
  209. ' Converts a given temperature from Delisle to Kelvin.
  210. function DelisleToKelvin(temperature)
  211. DelisleToKelvin = 373.15 - temperature * 2 / 3
  212. end function
  213.  
  214. ' Converts a given temperature from Delisle to Newton.
  215. function DelisleToNewton(temperature)
  216. DelisleToNewton = 33 - temperature * 11 / 50
  217. end function
  218.  
  219. ' Converts a given temperature from Delisle to Rankine.
  220. function DelisleToRankine(temperature)
  221. DelisleToRankine = 671.67 - temperature * 6 / 5
  222. end function
  223.  
  224. ' Converts a given temperature from Delisle to Reaumur.
  225. function DelisleToReaumur(temperature)
  226. DelisleToReaumur = 80 - temperature * 8 / 15
  227. end function
  228.  
  229. ' Converts a given temperature from Delisle to Romer.
  230. function DelisleToRomer(temperature)
  231. DelisleToRomer = 60 - temperature * 7 / 20
  232. end function
  233.  
  234. ' Converts a given temperature from Fahrenheit to Celsius.
  235. function FahrenheitToCelsius(temperature)
  236. FahrenheitToCelsius = (temperature - 32) * 5 / 9
  237. end function
  238.  
  239. ' Converts a given temperature from Fahrenheit to Delisle.
  240. function FahrenheitToDelisle(temperature)
  241. FahrenheitToDelisle = (212 - temperature) * 5 / 6
  242. end function
  243.  
  244. ' Converts a given temperature from Fahrenheit to Kelvin.
  245. function FahrenheitToKelvin(temperature)
  246. FahrenheitToKelvin = (temperature - 32) * 5 / 9 + 273.15
  247. end function
  248.  
  249. ' Converts a given temperature from Fahrenheit to Newton.
  250. function FahrenheitToNewton(temperature)
  251. FahrenheitToNewton = (temperature - 32) * 11 / 60
  252. end function
  253.  
  254. ' Converts a given temperature from Fahrenheit to Rankine.
  255. function FahrenheitToRankine(temperature)
  256. FahrenheitToRankine = temperature + 459.67
  257. end function
  258.  
  259. ' Converts a given temperature from Fahrenheit to Reamur.
  260. function FahrenheitToReaumur(temperature)
  261. FahrenheitToReaumur = (temperature - 32) * 4 / 9
  262. end function
  263.  
  264. ' Converts a given temperature from Fahrenheit to Romer.
  265. function FahrenheitToRomer(temperature)
  266. FahrenheitToRomer = (temperature - 32) * 7 / 24 + 7.5
  267. end function
  268.  
  269. ' Converts a given temperature from Kelvin to Celsius.
  270. function KelvinToCelsius(temperature)
  271. KelvinToCelsius = temperature - 273.15
  272. end function
  273.  
  274. ' Converts a given temperature from Kelvin to Delisle.
  275. function KelvinToDelisle(temperature)
  276. KelvinToDelisle = (373.15 - temperature) * 3 / 2
  277. end function
  278.  
  279. ' Converts a given temperature from Kelvin to Fahrenheit.
  280. function KelvinToFahrenheit(temperature)
  281. KelvinToFahrenheit = (temperature - 273.15) * 9 / 5 + 32
  282. end function
  283.  
  284. ' Converts a given temperature from Kelvin to Newton.
  285. function KelvinToNewton(temperature)
  286. KelvinToNewton = (temperature - 273.15) * 33 / 100
  287. end function
  288.  
  289. ' Converts a given temperature from Kelvin to Rankine.
  290. function KelvinToRankine(temperature)
  291. KelvinToRankine = temperature * 1.8
  292. end function
  293.  
  294. ' Converts a given temperature from Kelvin to Reaumur.
  295. function KelvinToReaumur(temperature)
  296. KelvinToReaumur = (temperature - 273.15) * 4 / 5
  297. end function
  298.  
  299. ' Converts a given temperature from Kelvin to Romer.
  300. function KelvinToRomer(temperature)
  301. KelvinToRomer = (temperature - 273.15) * 21 / 40 + 7.5
  302. end function
  303.  
  304. ' Converts a given temperature from Newton to Celsius.
  305. function NewtonToCelsius(temperature)
  306. NewtonToCelsius = temperature * 100 / 33
  307. end function
  308.  
  309. ' Converts a given temperature from Newton to Delisle.
  310. function NewtonToDelisle(temperature)
  311. NewtonToDelisle = (33 - temperature) * 50 / 11
  312. end function
  313.  
  314. ' Converts a given temperature from Newton to Fahrenheit.
  315. function NewtonToFahrenheit(temperature)
  316. NewtonToFahrenheit = temperature * 60 / 11 + 32
  317. end function
  318.  
  319. ' Converts a given temperature from Newton to Kelvin.
  320. function NewtonToKelvin(temperature)
  321. NewtonToKelvin = temperature * 100 / 33 + 273.15
  322. end function
  323.  
  324. ' Converts a given temperature from Newton to Rankine.
  325. function NewtonToRankine(temperature)
  326. NewtonToRankine = temperature * 60 / 11 + 491.67
  327. end function
  328.  
  329. ' Converts a given temperature from Newton to Reaumur.
  330. function NewtonToReaumur(temperature)
  331. NewtonToReaumur = temperature * 80 / 33
  332. end function
  333.  
  334. ' Converts a given temperature from Newton to Romer.
  335. function NewtonToRomer(temperature)
  336. NewtonToRomer = temperature * 35 / 22 + 7.5
  337. end function
  338.  
  339. ' Converts a given temperature from Rankine to Celsius.
  340. function RankineToCelsius(temperature)
  341. RankineToCelsius = (temperature / 1.8) - 273.15
  342. end function
  343.  
  344. ' Converts a given temperature from Rankine to Delisle.
  345. function RankineToDelisle(temperature)
  346. RankineToDelisle = (671.67 - temperature) * 5 / 6
  347. end function
  348.  
  349. ' Converts a given temperature from Rankine to Fahrenheit.
  350. function RankineToFahrenheit(temperature)
  351. RankineToFahrenheit = temperature - 459.67
  352. end function
  353.  
  354. ' Converts a given temperature from Rankine to Kelvin.
  355. function RankineToKelvin(temperature)
  356. RankineToKelvin = temperature / 1.8
  357. end function
  358.  
  359. ' Converts a given temperature from Rankine to Newton.
  360. function RankineToNewton(temperature)
  361. RankineToNewton = (temperature - 491.67) * 11 / 60
  362. end function
  363.  
  364. ' Converts a given temperature from Rankine to Reaumur.
  365. function RankineToReaumur(temperature)
  366. RankineToReaumur = (temperature * 5 / 9 - 273.15) * 4 / 5
  367. end function
  368.  
  369. ' Converts a given temperature from Rankine to Romer.
  370. function RankineToRomer(temperature)
  371. RankineToRomer = (temperature - 491.67) * 7 / 24 + 7.5
  372. end function
  373.  
  374. ' Converts a given temperature from Reaumur to Celsius.
  375. function ReaumurToCelsius(temperature)
  376. ReaumurToCelsius = temperature * 5 / 4
  377. end function
  378.  
  379. ' Converts a given temperature from Reaumur to Delisle.
  380. function ReaumurToDelisle(temperature)
  381. ReaumurToDelisle = (80 - temperature) * 15 / 8
  382. end function
  383.  
  384. ' Converts a given temperature from Reaumur to Fahrenheit.
  385. function ReaumurToFahrenheit(temperature)
  386. ReaumurToFahrenheit = temperature * 9 / 4 + 32
  387. end function
  388.  
  389. ' Converts a given temperature from Reaumur to Kelvin.
  390. function ReaumurToKelvin(temperature)
  391. ReaumurToKelvin = temperature * 5 / 4 + 273.15
  392. end function
  393.  
  394. ' Converts a given temperature from Reaumur to Newton.
  395. function ReaumurToNewton(temperature)
  396. ReaumurToNewton = temperature * 33 / 80
  397. end function
  398.  
  399. ' Converts a given temperature from Reaumur to Rankine.
  400. function ReaumurToRankine(temperature)
  401. ReaumurToRankine = temperature * 9 / 4 + 491.67
  402. end function
  403.  
  404. ' Converts a given temperature from Reaumur to Romer.
  405. function ReaumurToRomer(temperature)
  406. ReaumurToRomer = temperature * 21 / 32 + 7.5
  407. end function
  408.  
  409. ' Converts a given temperature from Romer to Celsius.
  410. function RomerToCelsius(temperature)
  411. RomerToCelsius = (temperature - 7.5) * 40 / 21
  412. end function
  413.  
  414. ' Converts a given temperature from Romer to Delisle.
  415. function RomerToDelisle(temperature)
  416. RomerToDelisle = (60 - temperature) * 20 / 7
  417. end function
  418.  
  419. ' Converts a given temperature from Romer to Fahrenheit.
  420. function RomerToFahrenheit(temperature)
  421. RomerToFahrenheit = (temperature - 7.5) * 24 / 7 + 32
  422. end function
  423.  
  424. ' Converts a given temperature from Romer to Kelvin.
  425. function RomerToKelvin(temperature)
  426. RomerToKelvin = (temperature - 7.5) * 40 / 21 + 273.15
  427. end function
  428.  
  429. ' Converts a given temperature from Romer to Newton.
  430. function RomerToNewton(temperature)
  431. RomerToNewton = (temperature - 7.5) * 22 / 35
  432. end function
  433.  
  434. ' Converts a given temperature from Romer to Rankine.
  435. function RomerToRankine(temperature)
  436. RomerToRankine = (temperature - 7.5) * 24 / 7 + 491.67
  437. end function
  438.  
  439. ' Converts a given temperature from Romer to Reaumur.
  440. function RomerToReaumur(temperature)
  441. RomerToReaumur = (temperature - 7.5) * 32 / 21
  442. end function
  443. %>

Report this snippet  

You need to login to post a comment.