all groups > sql server reporting services > november 2006 >
You're in the

sql server reporting services

group:

Code - Integer, Nothing vs Zero



Code - Integer, Nothing vs Zero SteveH
11/20/2006 4:19:01 PM
sql server reporting services: The piece of code below attempts to convert minutes to a time string.

The problem I am having is if the value of Minutes is NULL, it treats it as
zero.

Has anyone got any suggestions ?

Thanks
Steve
--------------------------------------------

Public Function MinutesToTime(ByVal Minutes AS Integer)
On Error GoTo errorhandler

Dim mins
Dim hrs

If IsNothing(Minutes) Then
MinutesToTime = ""
Else
hrs = Fix(Minutes / 60)
mins = Minutes - (hrs * 60)

If mins < 10 Then mins = "0" & mins

MinutesToTime = hrs & ":" & mins
End If

Exit Function

errorhandler:
MinutesToTime = "##:##"

End Function
Re: Code - Integer, Nothing vs Zero Chris Conner
11/21/2006 10:31:17 AM
First off this is a function, you should be explicit on your return values.
You have two DIM's without specifing the type... then you have a check for
NULL (if nothing) you return a string... so which is it?
What happens if the minutes is actually 0 - what would you return? Would it
be an empty string or "00:00" ?? If that is the case, then why not, for NULL
values, return "00:00" - the same as if you specified 0 minutes?

=-Chris

[quoted text, click to view]

Re: Code - Integer, Nothing vs Zero SteveH
11/21/2006 2:49:01 PM
Thanks Chris for your reply

I am wanting to pass in an integer representing minutes and return a string
that looks like a time as per the following examples.

67 returns "1:07"
0 returns "0:00"
NULL returns ""

My problems is that when NULL is passed in I am currently getting "0:00"
instead of "".

I have tried using IsNull function but I get a compilation error "Name
'IsNull' is not declared."

[quoted text, click to view]
Re: Code - Integer, Nothing vs Zero aaron.kempf NO[at]SPAM gmail.com
11/22/2006 12:29:10 PM
Reporting Services doesn't support 'code reuse'
so I would reccomend just doing this in Microsoft Access; it would be a
simple format string there; right?

-Aaron


[quoted text, click to view]
Re: Code - Integer, Nothing vs Zero SteveH
11/27/2006 5:49:02 PM
Finally found a solution and thought I would post it here for anyone who has
the same problem.

datatype needed to be Nullable(Of Integer) instead of Integer
Public Function MinutesToTime(ByVal Minutes As Nullabe(Of Integer)) AS
String

then use HasValue instead of IsNothing
If Minutes.HasValue Then

and Minutes.Value

[quoted text, click to view]
AddThis Social Bookmark Button