Code:
'Total Heat Gain From Soil On Pipe Run Calculaiton
    Public Function totalheatgainfromsoilonpiperuncal(ByVal totallengthofpiperun As Double, ByVal HeatGain As Double) As Double


        HeatGain = HeatGainCalculation(HeatTransmissionCoefficientforASinglePipe, SoilTemp, SupplyTemp)

        Dim TotalHeatGainFromSoilonPipeRun As Double = totallengthofpiperun * HeatGain
        Dim RoundedTotalHeatGainFromSoilonPipeRun As Double = Math.Round(TotalHeatGainFromSoilonPipeRun, 3)

        If RoundedTotalHeatGainFromSoilonPipeRun > 0 Then
            lblTotalHeatGainFromSoilOnPipeRun.Text = " Total Heat Gain From Soil On Pipe Run : " & RoundedTotalHeatGainFromSoilonPipeRun & " Watts "
        ElseIf RoundedTotalHeatGainFromSoilonPipeRun < 0 Then
            lblTotalHeatGainFromSoilOnPipeRun.Text = " Total Heat Loss From Soil On Pipe Run : " & RoundedTotalHeatGainFromSoilonPipeRun & " Watts "
        End If

        Return RoundedTotalHeatGainfromsoilonPipeRun
    End Function
    'HeatGain Calculation
    Public Function HeatGainCalculation(ByVal HeatTransmissionCoefficientforASinglePipe As Double,
                                    ByVal SoilTemp As Double,
                                    ByVal SupplyTemp As Double) As Double

        InternalDiameterofCasingPipe = internaldiamofcasingpipecalculation(Externaldiameterofcarrierpipe, InsulationThickness)
        ExternalDiameterofCasingPipe = externaldiamofcasingpipe(InternalDiameterofCasingPipe, JacketThickness)
        LayingDepthToCenterlineOfPipe = layingdepthtocenterlineofpipecal(LayingDepthtoTopofPipe, ExternalDiameterofCasingPipe)
        InternalDiameterofCarrierPipe = InternalDiamCarrierPipeCalculation(Externaldiameterofcarrierpipe, CarrierPipeWallThickness)

        ThermalResistanceofTheInsulation = thermalresistanceofinsulationcal(ThermalConductivityofInsulation, InternalDiameterofCasingPipe, Externaldiameterofcarrierpipe)
        ThermalResistanceOfTheCarrierPipe = thermalresistanceofthecarrierpipecal(ThermalConductivityofCarrierPipe, Externaldiameterofcarrierpipe, InternalDiameterofCarrierPipe)
        ThermalResistanceofTheJacketPipe = thermalresistanceofthejacketpipecal(ThermalConductivityofCasingPipe, ExternalDiameterofCasingPipe, InternalDiameterofCasingPipe)
        ThermalResistanceOfTheSoil = thermalresistanceofsoilcal(ThermalConductivityofSoil, LayingDepthToCenterlineOfPipe, ExternalDiameterofCasingPipe)
        HeatTransmissionCoefficientforASinglePipe = HeatTransmissionCoefficientforAsinglePipeCalculation(ThermalResistanceofTheInsulation, ThermalResistanceOfTheCarrierPipe,
                                                                                                         ThermalResistanceofTheJacketPipe, ThermalResistanceOfTheSoil)

        Dim HeatGain As Double = HeatTransmissionCoefficientforASinglePipe * (SoilTemp - SupplyTemp)
        Dim RoundedHeatGain As Double = Math.Round(HeatGain, 3)

        If RoundedHeatGain > 0 Then
            lblHeatGain.Text = " HeatGain : " & RoundedHeatGain & " W/m "
        ElseIf RoundedHeatGain < 0 Then
            lblHeatGain.Text = " HeatLoss : " & RoundedHeatGain & " W/m "

        End If
        Return HeatGain

    End Function
    ' Increase in supply temp at outlet
    Public Function increaseinsupplytempatoutletcal(ByVal totalheatgainfromsoilonpiperun As Double, ByVal flowrateimperial As Double) As Double


        totalheatgainfromsoilonpiperun = totalheatgainfromsoilonpiperuncal(TotalLengthofPipeRun, HeatGain)
        flowrateimperial = ConvertVariableToImperial(SoilTemp, SupplyTemp, CarrierPipeWallThickness, InsulationThickness, JacketThickness, Externaldiameterofcarrierpipe,
                                                     LayingDepthtoTopofPipe, TotalLengthofPipeRun, FlowRate, Temperaturetoreach)
        Dim IncreaseInSupplyTemperatureAtOutlet As Double = totalheatgainfromsoilonpiperun / (flowrateimperial * 998 * 4190 * 0.000063)
        Dim RoundedIncreaseInsupplyTemperatureAtOutlet As Double = Math.Round(IncreaseInSupplyTemperatureAtOutlet, 3)

        If RoundedIncreaseInsupplyTemperatureAtOutlet > 0 Then
            lblIncreaseinSupplyTemperatureatOutlet.Text = " Incease in supply temperature at outlet : " & RoundedIncreaseInsupplyTemperatureAtOutlet & " Degree C"
        ElseIf RoundedIncreaseInsupplyTemperatureAtOutlet < 0 Then
            lblIncreaseinSupplyTemperatureatOutlet.Text = " Decrease in supply temperature at outlet : " & RoundedIncreaseInsupplyTemperatureAtOutlet & " Degree C"
        End If

        Return RoundedIncreaseInSupplyTemperatureAtOutlet
    End Function
    ' Heat transmission coefficient for a single pipe calculation
    Public Function HeatTransmissionCoefficientforAsinglePipeCalculation(ByVal ThermalResistanceofTheInsulation As Double,
                                                                         ByVal ThermalResistanceOfTheCarrierPipe As Double,
                                                                         ByVal ThermalResistanceofTheJacketPipe As Double,
                                                                         ByVal ThermalResistanceOftheSoil As Double) As Double

        ThermalResistanceofTheInsulation = thermalresistanceofinsulationcal(ThermalConductivityofInsulation, InternalDiameterofCasingPipe, Externaldiameterofcarrierpipe)
        ThermalResistanceOfTheCarrierPipe = thermalresistanceofthecarrierpipecal(ThermalConductivityofCarrierPipe, Externaldiameterofcarrierpipe, InternalDiameterofCarrierPipe)
        ThermalResistanceofTheJacketPipe = thermalresistanceofthejacketpipecal(ThermalConductivityofCasingPipe, ExternalDiameterofCasingPipe, InternalDiameterofCasingPipe)
        ThermalResistanceOftheSoil = thermalresistanceofsoilcal(ThermalConductivityofSoil, LayingDepthToCenterlineOfPipe, ExternalDiameterofCasingPipe)

        Dim HeatTransmissionCoefficientforASinglePipe As Double = (1 / (ThermalResistanceofTheInsulation + ThermalResistanceOfTheCarrierPipe + ThermalResistanceofTheJacketPipe + ThermalResistanceOftheSoil))

        Return HeatTransmissionCoefficientforASinglePipe

    End Function

    ' Velocity Calculation

    Public Function VelocityCalculation(ByVal txtFlowRate As Double, ByVal txtExternaldiameterofcarrierpipe As Double, ByVal txtCarrierPipeWallThickness As Double) As Double

        Dim InternalDiameterofCarrierPipe As Double = (Externaldiameterofcarrierpipe - 2) * (CarrierPipeWallThickness / 1000)
        Dim Velocity As Double = FlowRate * 0.001 / (3.1416 * InternalDiameterofCarrierPipe * (InternalDiameterofCarrierPipe / 4))
        Dim RoundedVelocity = Math.Round(Velocity, 3)
        lblVelocity.Text = " Velocity : " & RoundedVelocity & " m / sec "



        Return Velocity

        Exit Function
    End Function