S
Stephany Young
Return hh & "h " & mm & "m " & ss & "s"
Stephany said:Return hh & "h " & mm & "m " & ss & "s"
I am getting the following warning for the below function. I understand what
it means but how do I handle a null reference? Then how do I pass the
resulting value?
Regards
Warning 1 Function 'Dec2hms' doesn't return a value on all code paths. A
null reference exception could occur at run time when the result is used.
G:\Project Development\Visual Studio
2005\Projects\Ascension\Ascension\SwephConversions.vb 64 3 Ascension
' Convert decimal hours to hours/minutes/seconds
Public Function Dec2hms(ByVal x As Decimal) As String
Dim hh As Int32, mm As Int32, ss As Decimal, remainder As Decimal
'Dim x a decimal, hh as integer
hh = CType(x, Integer)
remainder = (x - hh)
mm = CType((remainder * 60), Integer)
remainder = ((remainder * 60) - mm)
ss = Int(remainder * 60)
remainder = ((remainder * 60) - ss)
If remainder >= 0.5 Then
ss = ss + 1
Else
ss = ss
End If
hms = hh & "h " & mm & "m " & ss & "s"
End Function
Stephany Young said:Without going into the why's and wherefore's, some types in .NET are
called value types. These include String, Integer, DateTime and Boolean
among others. These are usually implemented as a Structure rather than as
Class. A type implemented as a Class is usually called a reference type.
Because of the above, the default value for an uninitialised string isIn general, you can assing Nothing to a variable of a reference type and
that variable is considered to be unassigned.
When you assign Nothing to a variable of a value type, then, behind the
scenes, the default value for that particular value type is substituted.
The default value for a String is String.Empty, the default value for an
Integer is 0, the default value for a DateTime is 01/01/0001, the default
value for a Boolean is False and so on and so forth.