Strange Problem with Report

Stimulsoft Reports.NET discussion
Post Reply
spv123
Posts: 26
Joined: Mon Oct 02, 2006 8:07 am
Location: Sheffield, UK

Strange Problem with Report

Post by spv123 »

I generate my report using the following vb.net code :

Code: Select all

Private Function CreateStimulReport(ByVal FormName As String, ByVal FieldNames() As String, ByVal FieldData() As String) As Stimulsoft.Report.StiReport

        ' Create and Return Report

        Dim tmpReport(0) As Stimulsoft.Report.StiReport
        tmpReport(0) = New Stimulsoft.Report.StiReport


        tmpReport(0).Load("c:\dms\forms\" & FormName & ".mrt")
        Dim PageNo As Int32 = 0
        Dim dct As Int32 = FieldNames.GetLength(0) - 1
        For cnt As Int32 = 0 To dct

            If FieldNames(cnt) = "@PAGE" Then
                ' Create New Page
                If tmpReport(PageNo).Pages.Count > 0 Then
                    tmpReport(PageNo).Compile()
                    tmpReport(PageNo).Render()
                    If PageNo > 0 Then
                        tmpReport(0).RenderedPages(tmpReport(0).RenderedPages.Count - 1).Report = tmpReport(0)
                        tmpReport(0).RenderedPages.AddRange(tmpReport(PageNo).RenderedPages)
                    End If
                    ReDim Preserve tmpReport(tmpReport.GetLength(0))
                    PageNo = PageNo + 1
                    tmpReport(PageNo) = New Stimulsoft.Report.StiReport
                    tmpReport(PageNo).Load("c:\dms\forms\" & FormName & ".mrt")

                End If
            Else
                If FieldData(cnt).Trim  "" Then
                    Try
                        Debug.WriteLine("Setting Field [" & FieldNames(cnt) & "] = " & FieldData(cnt))
                        If FieldData(cnt).StartsWith(" ") Then FieldData(cnt) = Chr(31) & FieldData(cnt)
                        tmpReport(PageNo).Dictionary.Variables(FieldNames(cnt)).Value = FieldData(cnt).TrimEnd(" ")
                    Catch
                        Debug.WriteLine("Err with field & " & FieldNames(cnt) & "  = " & Err.Description)
                    End Try
                End If
            End If

        Next
        Try
            If tmpReport(PageNo).Pages.Count > 0 Then

                tmpReport(PageNo).Compile()
                tmpReport(PageNo).Render()
                If PageNo > 0 Then
                    tmpReport(0).RenderedPages(tmpReport(0).RenderedPages.Count - 1).Report = tmpReport(0)
                    tmpReport(0).RenderedPages.AddRange(tmpReport(PageNo).RenderedPages)
                End If
            End If
        Catch
            Debug.WriteLine("error = " & Err.Number & " " & Err.Description)
        End Try

        ' tmpReport(0).Show()
        Return tmpReport(0)
    End Function
Sometimes this works ok, sometimes it comes up with a compile error.

Taking a debug trace from the above code on a form that works ok gives:

Setting Field [Field1] = SERVICE SALE INVOICE No: 12328 PAGE 1 17/10/06
Setting Field [Field3] = Mrs J KELSEY
Setting Field [Field4] = 2 OAKLANDS
Setting Field [Field5] = BRISTON
Setting Field [Field6] = MELTON CONSTABLE
Setting Field [Field7] = NORFOLK
Setting Field [Field8] = NR24 2HE O/N: NONE
Setting Field [Field10] = Vehicle: MITSUBISHI - CARISMA Reg: YW02DAU Miles: 55856 Job: 2771
Setting Field [Field11] = ..............................................................................
Setting Field [Field12] = REQUEST A TO HAVE HEADLIGHTS ALTERED.
Setting Field [Field13] = labour vat rate
Setting Field [Field14] = TO HAVE HEADLIGHTS ALTERED. CHECKED LIGHT OPERATION AND
Setting Field [Field15] = BOTH DIP BEAMS WERE FAULTY. CHECKED FUSES, FUSES OK.
Setting Field [Field16] = CHECKED FEEDS TO BULBS, FEEDS OK. FAULTY BULBS. REPLACED
Setting Field [Field17] = BOTH BULBS.
Setting Field [Field18] = 0.00 0.00 17.5%
Setting Field [Field19] = TOTAL CHARGE FOR REQUEST A 0.00
Setting Field [Field20] = ..............................................................................
Setting Field [Field22] = YOUR SERVICE ADVISOR IS KATY GANT
Setting Field [Field51] = SERVICE TOTAL 0.00
Setting Field [Field52] = VAT TOTAL 0.00
Setting Field [Field53] = INVOICE TOTAL 0.00
Setting Field [Field55] = RAISED BY BRANCH 1
'dms.exe': Loaded '5fik3j6b', No symbols loaded.
A similar one that gives a compile error is :
Setting Field [Field1] = SERVICE INTERNAL SALE A/C No: 1231 INVOICE No: 12332 PAGE 1 17/10/06
Setting Field [Field3] = POLICY ADJ/GOODWILL SERVICE
Setting Field [Field4] = FOURSONS
Setting Field [Field5] = Hall Road
Setting Field [Field7] = NORWICH
Setting Field [Field9] = NR4 6DG O/N: NONE
Setting Field [Field11] = Vehicle: MITSUBISHI - CARISMA Reg: YW02DAU Miles: 55856 Job: 2771
Setting Field [Field12] = ..............................................................................
Setting Field [Field13] = REQUEST A TO HAVE HEADLIGHTS ALTERED.
Setting Field [Field14] = labour vat rate
Setting Field [Field15] = TO HAVE HEADLIGHTS ALTERED. CHECKED LIGHT OPERATION AND
Setting Field [Field16] = BOTH DIP BEAMS WERE FAULTY. CHECKED FUSES, FUSES OK.
Setting Field [Field17] = CHECKED FEEDS TO BULBS, FEEDS OK. FAULTY BULBS. REPLACED
Setting Field [Field18] = BOTH BULBS.
Setting Field [Field19] = 0.00 0.00 0%
Setting Field [Field20] = notes: CUSTOMER NOT HAPPY WITH PAYING
Setting Field [Field21] = FOR BULBS - AS GOODWILLL F.O.C
Setting Field [Field22] = part no description retail qty price vat rate
Setting Field [Field23] = DLB600472 BULB 12V 60/55W HALOGEN " 6.31 2 6.50 0.00 0%
Setting Field [Field24] = TOTAL CHARGE FOR REQUEST A 6.50
Setting Field [Field25] = ..............................................................................
Setting Field [Field27] = YOUR SERVICE ADVISOR IS KATY GANT
Setting Field [Field52] = SERVICE TOTAL 6.50
Setting Field [Field53] = VAT TOTAL 0.00
Setting Field [Field54] = INVOICE TOTAL 6.50
Setting Field [Field56] = RAISED BY BRANCH 1
error = 5 C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\m4gznilr.0.vb(561,0) : error BC30205: End of statement expected.
The thread '' (0x824) has exited with code 0 (0x0).
The form can be downloaded from Stimulsoft Report (rename as headedpaper1.mrt)

Any thoughts on what is going wrong?

This is on the latest build of Stimulsoft.
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

Strange Problem with Report

Post by Brendan »

Hi spv123

I was just examining your code and report and was just wondering have you considered using a Databand to render your fields. I see you have roughly 60 static lines in the report which each set from a loop in code. If the FieldName = "@PAGE" you create a new page and add it to the output.

You could load your FieldNames/FieldData into a collection object and register this as a Datasource for the StimulReport.
Then just add a databand to the report and drop in the FieldData column and have the report render the data for you.

You can then also use the BeforePrint event of the databand to check for "@PAGE" and if it's true you can tell the Report to begin rendering to New Page.

If you would like some sort of sample I could provide you with one but your requirements may be more complex than presented, however I'd be happy to provide one.
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Strange Problem with Report

Post by Vital »

spv123 wrote: Setting Field [Field23] = DLB600472 BULB 12V 60/55W HALOGEN " 6.31 2 6.50 0.00 0%
Problem in following line. It contain char ". If you assign variable before compilation
then your strings declaration must be compatible with vb.net specifications. So you need replace
char " by \". If you assign variables after compilation with following code:

report["VaraibleName"] = "123";

In this case you can use any format.

If you are use latest builds (starts from 2006.4) you can specify other format of variable (only strings not expression).

Thank you.
spv123
Posts: 26
Joined: Mon Oct 02, 2006 8:07 am
Location: Sheffield, UK

Strange Problem with Report

Post by spv123 »

Brendan

It's working this way because the data coming in to the function was written to support an alternative reporting product which I still need to support until I replace all the forms - therefore I have had to be constrained to work in the same way...

Vital - thanks for the tip, I'm trying it now but it sounds reasonable! Would be nice if the error could have been fired as you set the variable rather than a random error in the compile phase! I might have spotted it myself then!

Thanks and regards
Simon
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Strange Problem with Report

Post by Vital »

I understand, but we can't parse c# or vb.net expression - this is not easy way. So in latest build variable can work in two mode:
expresion and simple value. We do this changes to prevent similar errors.

Thank you.
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

Strange Problem with Report

Post by Brendan »

Hi Simon,
yeah I thought it may of been used for something else or that the data was coming from a legacy system.

You can review the sample here if you wish:
http://rapidshare.de/files/37216934/RptSample.zip.html

My VB.Net skills are kind of rusty as it's been a number of years since I've used them :)
All the best,
Brendan
Post Reply