Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ISDATE function fails in CR8.5

Status
Not open for further replies.

dean12

MIS
Oct 23, 2001
273
US
I'm getting a strange error in my user function library (UFL). I have a function that accepts a string and checks to see if it is a date like this:


Public Function psToDate(ByVal YYYYMMDD As String) As Date
'
' Convert the date held in the string to an actual date field
'

On Error GoTo ErrorTrap
YYYYMMDD = "12012001"
MsgBox "pstodate=" & YYYYMMDD
If IsDate(YYYYMMDD) Then
MsgBox "pstodate convert to date"
psToDate = CDate(YYYYMMDD)
MsgBox "pstodate returns date"
Else
psToDate = Null
MsgBox "pstodate returns null"
End If
Exit Function

ErrorTrap:
MsgBox "?Trapped error in psToDate"

End Function

-------------------------------------------------------

This fails on the IF ISDATE(....... statement. All of this looks good to me and the message I get is the dreaded "Memory Full" error.

The only thing I can think of is that CR supports the ISDATE function directly and maybe there is some type of conflict but that seems to be a long shot as that would preclude the use of almost all the VB functions.

Any ideas?

 
This UFL has already been written. Your formula should be
NumberToDate({NumberField}). This function takes an 8 digit integer in teh YYYYMMDD format and converts it to a true date. If the field is a string, just convert it to a number first, then use the NumberToDate() function.

You can download it here:


Software Support for Macola, Crystal Reports and Goldmine
714-348-0964
dgilsdorf@mchsi.com
 
Thanks for letting me know this - especially since ISDATE does not recognize YYYYMMDD as a real date anyway.

But the question still remains, and this is the bigger issue, why does this fail rather than simply return FALSE?

 
YYYYMMDD = "12012001"

Somehow this doesn't look like the proper format...maybe you are getting a valid none date....this looks like the year 1201 with month 20 (definately illegal) and day 01

hope this is all it is :) Jim Broadbent
 
I agree, this date format is not going to work. However, the routine aborts and takes the "on error" trap rather than return TRUE or FALSE.

When I code up the same functionality directly in VB6, no failure - TRUE or FALSE - but it doesn't simply die.

In CR8.5, without the ON ERROR statement, the report aborts with MEMORY FULL and that's not the right thing to do.
 
I was just reading the CR help files, and it does not appear that IsDate() supports an 8 digit string for this.

Check it out and see what you think. Software Support for Macola, Crystal Reports and Goldmine
714-348-0964
dgilsdorf@mchsi.com
 
This does introduce an interesting question:

Since CR8.5 offers an ISDATE function call and VB offers an ISDATE function call, which is being used when in a UFL which is VB code and created using VB Studio?

I have tested the use of "20021212" against code written and executed within VB Studio and it does not fail. It doesn't detect it as a date which is unfortunate but more importantly it does not simply abort or die.
 
Oh, and by the way the NumberToDate function takes a numeric - my value here is a string.
 
Dean12 - to use the NumberToDate function with a string...just convert the string to a number with ToNumber

Jim Broadbent
 
Dean,

yes, I mentioned in my first post on this thread that you would need to convert that to a number if it is a string. Software Training and Support for Macola, Crystal Reports and Goldmine
714-348-0964
dgilsdorf@mchsi.com
 
Well yes that could be done I suspect.

Stupid thing about this is that you have to setup the formulas to convert to number, convert to date, etc. everytime you want a date formatted nicely on the report. No way to save those formulas that I can see from report to report so this gets tedious doing it over and over again. Guess I was just looking for a fast way to get the job done so I tried writing my own UFL.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top