Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Temperature conversion library for 4Test, Workbench and Silk4Net

Temperature conversion library for 4Test, Workbench and Silk4Net

SilkTest Classic does not contain any native utilities for temperature conversion. The attached include and class files contain conversions between the three most commonly-used temperature scales: Kelvin, Celsius and Fahrenheit.

For 4Test, to use the library in your testcases simply 'Use' the include file in your frame file. The conversion will return a maximum of six decimal places; this restriction is a result of the Val() conversion. If there are fewer than six decimal places required then Val() will append trailing zeroes to file the result. This does not affect the accuracy. 

For Workbench or Silk4Net add the class library as part of your project.

Please note that these conversions are subject to the usual operating system rounding errors. The vb.Net class uses arithmetic rather than banker rounding.

[ ] // ********************************************************
[ ] // Temperature conversions
[ ] // Input the temperature to be converted and the number of decimal places required
[ ] // ********************************************************
[ ] // Fahrenheit to Celsius
[-] real convertFC(real tempF, integer iPlaces)
    [ ] string sTemp=""
    [ ] real rTemp=(tempF-32)*5/9
    [ ] sTemp=Str(rTemp,10,iPlaces)
    [ ] return val(sTemp)
    [ ]
[ ] // Celsius to Fahrenheit
[-] real convertCF(real tempC, integer iPlaces)
    [ ] string sTemp=""
    [ ] real rTemp=(tempC*9/5)+32
    [ ] sTemp=Str(rTemp,10,iPlaces)
    [ ] return val(sTemp)
    [ ]
[ ] // Kelvin to Celsius
[-] real convertKC(real tempK, integer iPlaces)
    [ ] string sTemp=""
    [ ] real rTemp=tempK-273.15
    [ ] sTemp=Str(rTemp,10,iPlaces)
    [ ] return val(sTemp)
    [ ]
[ ] // Celsius to Kelvin
[-] real convertCK(real tempC, integer iPlaces)
    [ ] string sTemp=""
    [ ] real rTemp=tempC+273.15
    [ ] sTemp=Str(rTemp,10,iPlaces)
    [ ] return val(sTemp)
    [ ]
[ ] // Kelvin to Fahrenheit
[-] real convertKF(real tempK, integer iPlaces)
    [ ] string sTemp=""
    [ ] real rTemp
    [ ] rTemp=(tempK*9/5)-459.67
    [ ] sTemp=Str(rTemp,10,iPlaces)
    [ ] return val(sTemp)
    [ ]
[ ] // Fahrenheit to Kelvin
[-] real convertFK(real tempF, integer iPlaces)
    [ ] string sTemp=""
    [ ] real rTemp
    [ ] rTemp=(tempF+459.67)*5/9
    [ ] sTemp=Str(rTemp,10,iPlaces)
    [ ] return val(sTemp)

Workbench and Silk4Net

Public Class temperature

    ' --------------------------------------------------------------------------
    ' Rounding is done to arithmetic standard and not banker standard.
    ' --------------------------------------------------------------------------
    ' Fahrenheit to celsius
    Public Function convertFC(ByVal tempF As Double, ByVal decPlaces As Integer)

        Dim dTemp As Double = 0

        dTemp = (tempF - 32) * 5 / 9
        Math.Round(dTemp, decPlaces, MidpointRounding.AwayFromZero)

        Return dTemp
    End Function

    ' --------------------------------------------------------------------------
    ' Celsius to Fahrenheit
    Public Function convertCF(ByVal tempC As Double, ByVal decPlaces As Integer)

        Dim dTemp As Double = 0

        dTemp = (tempC * 9 / 5) + 32
        Math.Round(dTemp, decPlaces, MidpointRounding.AwayFromZero)

        Return dTemp
    End Function

    ' --------------------------------------------------------------------------
    ' Kelvin to Celsius
    Public Function convertKC(ByVal tempK As Double, ByVal decPlaces As Integer)

        Dim dTemp As Double = 0

        dTemp = tempK - 273.15
        Math.Round(dTemp, decPlaces, MidpointRounding.AwayFromZero)

        Return dTemp
    End Function

    ' --------------------------------------------------------------------------
    ' Celsius to Kelvin
    Public Function convertCK(ByVal tempC As Double, ByVal decPlaces As Integer)

        Dim dTemp As Double = 0

        dTemp = tempC + 273.15
        Math.Round(dTemp, decPlaces, MidpointRounding.AwayFromZero)

        Return dTemp
    End Function

    ' --------------------------------------------------------------------------
    ' Kelvin to Fahrenheit
    Public Function convertKF(ByVal tempK As Double, ByVal decPlaces As Integer)

        Dim dTemp As Double = 0

        dTemp = (tempK * 9 / 5) - 459.67
        Math.Round(dTemp, decPlaces, MidpointRounding.AwayFromZero)

        Return dTemp
    End Function

    ' --------------------------------------------------------------------------
    ' Fahrenheit to Kelvin
    Public Function convertFK(ByVal tempF As Double, ByVal decPlaces As Integer)

        Dim dTemp As Double = 0

        dTemp = (tempF + 459.67) * 5 / 9
        Math.Round(dTemp, decPlaces, MidpointRounding.AwayFromZero)

        Return dTemp
    End Function

End Class

4861.temperature.zip

temperatureVB.zip

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-10-29 17:09
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.