ENDOFCURRENTMONTH

Support for Crystal Reports within Jiwa.

ENDOFCURRENTMONTH

Postby pricerc » Fri May 21, 2021 1:25 pm

So I'm working migrating an old Jiwa 6 report to Jiwa 7.

I figure I'll use ENDOFCURRENTMONTH as a default value for one of the parameters.

As soon as I do, I get a FormatException error from "ToDouble".

I was a bit puzzled by this, so digging in the decompiled LoadReport:

Code: Select all
                            If (str10.ToUpper().IndexOf("ENDOFCURRENTMONTH") >= 0) Then
                                sysDateTime = Me.Manager.Database.SysDateTime
                                Dim num14 As Double = Conversions.ToDouble(sysDateTime.ToString("yyyy-MM-"))
                                sysDateTime = Me.Manager.Database.SysDateTime
                                Dim year As Integer = sysDateTime.Year
                                sysDateTime = Me.Manager.Database.SysDateTime
                                str10 = str10.Replace("ENDOFCURRENTMONTH", Conversions.ToString(num14 + CDbl(System.DateTime.DaysInMonth(year, sysDateTime.Month))))
                            End If


I am pretty sure that:
Code: Select all
Dim num14 As Double = Conversions.ToDouble(sysDateTime.ToString("yyyy-MM-"))


Will never work.

I couldn't find mention of ENDOFCURRENTMONTH in the bug database.

Does that mean that I am the first person to try and use this promising feature?

I've tried to figure out a workaround, but it's not clear from the documentation I've found so far (i.e. where I found out about ENDOFCURRENTMONTH) how complicated I can make the //DEFAULT formula.
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 509
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: ENDOFCURRENTMONTH

Postby Scott.Pearce » Fri May 21, 2021 4:28 pm

Yep that's a bug. The source code is using a "+" for string append instead of "&" (it's in VB .NET). Please log a dev issue.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 748
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 225

Re: ENDOFCURRENTMONTH

Postby pricerc » Fri May 21, 2021 4:43 pm

Scott.Pearce wrote:Yep that's a bug. The source code is using a "+" for string append instead of "&" (it's in VB .NET). Please log a dev issue.


I was about to comment on that not being the problem that I noticed, but then I realised that you're not looking at the decompiled code!

ILSpy decompiles it much more cleanly into a single line, which probably highlights the problem better (in hindsight):

Code: Select all
text11 = text11.Replace("ENDOFCURRENTMONTH", Conversions.ToString(Conversions.ToDouble(Manager.Database.SysDateTime.ToString("yyyy-MM-")) + (double)DateTime.DaysInMonth(Manager.Database.SysDateTime.Year, Manager.Database.SysDateTime.Month)));


The compiler obviously decided that you were trying to add two numbers. I'd be tempted to call that a bug in the compiler.

I mean, fair enough, DateTime.DaysInMonth returns a number, which the VB compiler is then helpfully converting to double for you.

But SysDateTime.ToString("yyyy-MM-") is clearly returning a string from a date, and I don't see a compelling reason why it would assume it to also be a number.

That kind of quirkiness is why I always code in VB with

Code: Select all
option strict on
option explicit on


between them, they usually catch that kind of thing at compile time - specifically, it would complain about trying to add a string to a number.
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 509
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: ENDOFCURRENTMONTH

Postby pricerc » Fri May 21, 2021 4:53 pm

JIWA-8121

instead of string concatenation, I'd go with something like:
Code: Select all
dim sysDateTime = Me.Manager.Database.SysDateTime
dim EOM = New DateTime(sysDateTime.Year, sysDateTime.Month, DateTime.DaysInMonth(sysDateTime.Year, sysDateTime.Month))

formula = formula.Replace("ENDOFCURRENTMONTH ", EOM.ToString("yyyy-MM-dd"))
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 509
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20


Return to Crystal Reports

Who is online

Users browsing this forum: No registered users and 2 guests