VBScript IsNull() function not working as I expect
Hi, I've written some VBScript code that takes an incoming integer that represents NumberOfSeconds and converts it to a time in words (e.g. "1d 3 h 34m 6s"). The code is below, unfortunately its failing with an error: "There is an error on line 2 of custom code : [BC30451] Name 'IsNull' is not declared." Any ideas? Thanks in advance Jamie Function TimeInWords (RemainderTimeInSeconds as Integer) AS String Dim ReturnValue As String IF (IsNull(RemainderTimeInSeconds) = True) RemainderTimeInSeconds = 0 END IF IF (RemainderTimeInSeconds > 86400) ReturnValue = TimeInDays(RemainderTimeInSeconds ) ELSE IF (RemainderTimeInSeconds > 3600) ReturnValue = TimeInHours(RemainderTimeInSeconds ) ELSE IF (RemainderTimeInSeconds > 60) ReturnValue = TimeInMinutes(RemainderTimeInSeconds ) ELSE ReturnValue = TimeInSeconds(RemainderTimeInSeconds ) End If Return ReturnValue End Function Function TimeInDays (RemainderTimeInSeconds AS Integer) AS String Return CStr(Round(RemainderTimeInSeconds / 86400)) + "d " + TimeInMinutes(RemainderTimeInSeconds Mod 86400) End Function Function TimeInHours (RemainderTimeInSeconds AS Integer) AS String Return CStr(Round(RemainderTimeInSeconds / 3600)) + "h " + TimeInMinutes(RemainderTimeInSeconds Mod 3600) End Function Function TimeInMinutes (RemainderTimeInSeconds AS Integer) AS String Return CStr(Round(RemainderTimeInSeconds / 60)) + "m " + TimeInSeconds(RemainderTimeInSeconds Mod 60) End Function Function TimeInSeconds (RemainderTimeInSeconds AS Integer) AS String Return CStr(RemainderTimeInSeconds) + "s" End Function http://sqlblog.com/blogs/jamie_thomson/ | @jamiet | About me
November 14th, 2010 5:38am

Not sure why it is, Well you can try other way.. I suppose you are going to use this function in a report text box. you can remove NULL check form you VB Script and use Following =IIF( ISNothing(RemainderTimeInSeconds), 0, YOUFUNCTIONCALL) Hope this will work for you.Gaurav Gupta http://sqlservermsbiblog.blogspot.com/
Free Windows Admin Tool Kit Click here and download it now
November 14th, 2010 2:32pm

Hi Gaurav, Good idea, I'll try that. Would still llike to know why I get the above error tho. Hoping someone from the SSRS team happens upon this. -Jamiehttp://sqlblog.com/blogs/jamie_thomson/ | @jamiet | About me
November 14th, 2010 4:06pm

Please checkout following as well http://forums.asp.net/t/1193832.aspx It say IsNULL is replaced by ISNothing, this might be the reason http://oreilly.com/catalog/vbdotnetnut/chapter/appa.html Gaurav Gupta http://sqlservermsbiblog.blogspot.com/
Free Windows Admin Tool Kit Click here and download it now
November 14th, 2010 4:49pm

Hi James, IsNull is a T-SQL function. For VB script, you should use IsNothing. thanks, Jerry
November 16th, 2010 3:33am

Hi James, IsNull is a T-SQL function. For VB script, you should use IsNothing. thanks, Jerry It seems then that there are multiple versions of VBScript knocking about. Who says so? W3C: http://www.w3schools.com/vbscript/func_isnull.asp Yet another reason to get rid of this abomination of a language which I should add to my SQL Developer Gap post.http://sqlblog.com/blogs/jamie_thomson/ | @jamiet | About me
Free Windows Admin Tool Kit Click here and download it now
November 16th, 2010 4:13am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics