ConverTemp
SwordfishUser.ConverTemp History
Hide minor edits - Show changes to output
Changed lines 1-2 from:
This a basic temperature conversion module to provide a range of conversions between units.
to:
This a basic temperature conversion module to provide a range of conversions between Temperature units.
Added lines 1-113:
This a basic temperature conversion module to provide a range of conversions between units.
A couple of examples of it in use
As Integers
=code [=
Include "ConvertTemp.bas"
Dim C As Integer
Dim F As Integer
Dim K As Integer
C = 254 // 25.4 deg.
F = ConvertTemp.CtoF(C)
K = ConvertTemp.CtoK(C) =]
As Floats
=code [=
Include "ConvertTemp.bas"
Dim C As Float
Dim F As Float
Dim K As Float
C = 25.4 // 25.4 deg.
F = ConvertTemp.CtoF(C)
K = ConvertTemp.CtoK(C) =]
And the module its self. Put away in the UserLibrary and it will be alway available for use at any time.
=code [=
{
****************************************************************
* Name : Temp.bas *
* Author : Darrel Taylor *
* Date : 10/5/2006 *
* Version : 1.0 *
* Notes : Temperature Conversion Module for Swordfish *
* Converts between Fahrenheit, Celsius and Kelvin *
* : You can use either Integers or Floats *
* Integers are multiplied by 10 for 1 decimal place *
* 25.4 would be stored as 254, -100.0 is -1000 *
* : Floats are obvious, 25.42 = 25.42 *
****************************************************************
* Functions: CtoF - Celsius to Fahrenheit *
* FtoC - Fahrenheit to Celsius *
* CtoK - Celsius to Kelvin *
* KtoC - Kelvin to Celsius *
* FtoK - Fahrenheit to Kelvin *
* KtoF - Kelvin to Fahrenheit *
****************************************************************
}
Module ConvertTemp
//------[ Celsius to Fahrenheit ]-------------------------------
Public Function CtoF (C As Integer) As Integer
Dim TempLI As LongInt
TempLI = C * 18 / 10 + 320
Result = Integer(TempLI)
End Function
//------
Public Function CtoF (C As Float) As Float
Result = C * 1.8 + 32
End Function
//------[ Fahrenheit to Celsius ]-------------------------------
Public Function FtoC (F As Integer) As Integer
Dim TempLI As LongInt
TempLI = (F - 320) * 10 / 18
Result = Integer(TempLI)
End Function
//------
Public Function FtoC (F As Float) As Float
Result = (F - 32) / 1.8
End Function
//------[ Celsius to Kelvin ]-----------------------------------
Public Function CtoK (C As Integer) As Integer
Result = C + 2730
End Function
//------
Public Function CtoK (C As Float) As Float
Result = C + 273.0
End Function
//------[ Kelvin to Celsius ]-----------------------------------
Public Function KtoC (K As Integer) As Integer
Result = K - 2730
End Function
//------
Public Function KtoC (K As Float) As Float
Result = K - 273.0
End Function
//------[ Fahrenheit to Kelvin ]--------------------------------
Public Function FtoK (F As Integer) As Integer
Result = CtoK(FtoC(F))
End Function
//------
Public Function FtoK (F As Float) As Float
Result = CtoK(FtoC(F))
End Function
//------[ Kelvin to Fahrenheit ]--------------------------------
Public Function KtoF (K As Integer) As Integer
Result = CtoF(KtoC(K))
End Function
//------
Public Function KtoF (K As Float) As Float
Result = CtoF(KtoC(K))
End Function =]
A couple of examples of it in use
As Integers
=code [=
Include "ConvertTemp.bas"
Dim C As Integer
Dim F As Integer
Dim K As Integer
C = 254 // 25.4 deg.
F = ConvertTemp.CtoF(C)
K = ConvertTemp.CtoK(C) =]
As Floats
=code [=
Include "ConvertTemp.bas"
Dim C As Float
Dim F As Float
Dim K As Float
C = 25.4 // 25.4 deg.
F = ConvertTemp.CtoF(C)
K = ConvertTemp.CtoK(C) =]
And the module its self. Put away in the UserLibrary and it will be alway available for use at any time.
=code [=
{
****************************************************************
* Name : Temp.bas *
* Author : Darrel Taylor *
* Date : 10/5/2006 *
* Version : 1.0 *
* Notes : Temperature Conversion Module for Swordfish *
* Converts between Fahrenheit, Celsius and Kelvin *
* : You can use either Integers or Floats *
* Integers are multiplied by 10 for 1 decimal place *
* 25.4 would be stored as 254, -100.0 is -1000 *
* : Floats are obvious, 25.42 = 25.42 *
****************************************************************
* Functions: CtoF - Celsius to Fahrenheit *
* FtoC - Fahrenheit to Celsius *
* CtoK - Celsius to Kelvin *
* KtoC - Kelvin to Celsius *
* FtoK - Fahrenheit to Kelvin *
* KtoF - Kelvin to Fahrenheit *
****************************************************************
}
Module ConvertTemp
//------[ Celsius to Fahrenheit ]-------------------------------
Public Function CtoF (C As Integer) As Integer
Dim TempLI As LongInt
TempLI = C * 18 / 10 + 320
Result = Integer(TempLI)
End Function
//------
Public Function CtoF (C As Float) As Float
Result = C * 1.8 + 32
End Function
//------[ Fahrenheit to Celsius ]-------------------------------
Public Function FtoC (F As Integer) As Integer
Dim TempLI As LongInt
TempLI = (F - 320) * 10 / 18
Result = Integer(TempLI)
End Function
//------
Public Function FtoC (F As Float) As Float
Result = (F - 32) / 1.8
End Function
//------[ Celsius to Kelvin ]-----------------------------------
Public Function CtoK (C As Integer) As Integer
Result = C + 2730
End Function
//------
Public Function CtoK (C As Float) As Float
Result = C + 273.0
End Function
//------[ Kelvin to Celsius ]-----------------------------------
Public Function KtoC (K As Integer) As Integer
Result = K - 2730
End Function
//------
Public Function KtoC (K As Float) As Float
Result = K - 273.0
End Function
//------[ Fahrenheit to Kelvin ]--------------------------------
Public Function FtoK (F As Integer) As Integer
Result = CtoK(FtoC(F))
End Function
//------
Public Function FtoK (F As Float) As Float
Result = CtoK(FtoC(F))
End Function
//------[ Kelvin to Fahrenheit ]--------------------------------
Public Function KtoF (K As Integer) As Integer
Result = CtoF(KtoC(K))
End Function
//------
Public Function KtoF (K As Float) As Float
Result = CtoF(KtoC(K))
End Function =]