Re: Function Warning - Null Reference

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I certainly prompted a debate.

Going back to my copy of .NET Framework 2.0 App Dev Foundation Training Kit,
I find that under the list of 'Other value Types' there is System.DateTime,
whilst under 'Common Reference Types' is listed System.String.

I do understand the common pitfalls that a newcomer to .NET may make in
handling text data.

All of the replying posts have been interesting and of value, I shall keep
the 'watched' flag on them all so that I can reference them from time to
time :-)

All your help has now enabled me to get my conversion of a VBA project to
VB.NET started and already producing results, many thanks.

Regards
Terry

"Terry" <news-grps@xxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:uQE7EocNHHA.3596@xxxxxxxxxxxxxxxxxxxxxxx
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




.



Relevant Pages

  • Re: Function Warning - Null Reference
    ... It's not just the 'newcomer' who can fall into the various traps. ... whilst under 'Common Reference Types' is listed ... Dim hh As Int32, mm As Int32, ss As Decimal, remainder As Decimal ...
    (microsoft.public.dotnet.languages.vb)
  • Function Warning - Null Reference
    ... Warning 1 Function 'Dec2hms' doesn't return a value on all code paths. ... null reference exception could occur at run time when the result is used. ... Dim hh As Int32, mm As Int32, ss As Decimal, remainder As Decimal ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Function Warning - Null Reference
    ... null reference exception could occur at run time when the result is used. ... Dim hh As Int32, mm As Int32, ss As Decimal, remainder As Decimal ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Circular motion in SR
    ... saying does not substantially change the value of what you are saying ... if the remainder is just as bad? ... preferred-frame reference to redefine all your lengths for you, ...     But after a few trial and error corrections, ...
    (sci.physics.relativity)
  • Re: Circular motion in SR
    ... saying does not substantially change the value of what you are saying ... if the remainder is just as bad? ... proof of a distance contraction that I could not disprove with the ... preferred-frame reference to redefine all your lengths for you, ...
    (sci.physics.relativity)