Arctic reports (reporting system - Windows)

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: Arctic reports (reporting system - Windows)

Post by captain_skank »

Hi srod,

Does this mean I can change a reports datasource including type e.g. ODBC and username/password through code ? cos that will make my life a whole heap easier.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Arctic reports (reporting system - Windows)

Post by srod »

You can change anything through code. The whole Pyrex designer uses the nxReport core module for all report modifications; it does not access any of the report's inner structures directly.
I may look like a mule, but I'm not a complete ass.
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: Arctic reports (reporting system - Windows)

Post by Neil »

srod wrote:No it will work on any valid report object regardless of how you loaded the report.

Before changing a subreport's datasource you need to set a current subreport with the \UseSubreport() method.

Yes the help for the nxReport core module is incomplete. The new version will not suffer such indignities! :)
Hi srod,

Thanks for all your advice - works great !!

Code: Select all

Procedure Button_Grades_Reports_ViewReport(EventType)

  If nxReport_CatchReport(?label_ReportStart, ?label_ReportEnd - ?label_ReportStart, @report) = #nxReport_OKAY
    report\UseSubreport("Page1", 0)
    sString = "SELECT * FROM Configuration, Grades "
    If GetGadgetState(gCheckBox_Grades_Reports_Sex_Male) And GetGadgetState(gCheckBox_Grades_Reports_Sex_Female)      
    ElseIf GetGadgetState(gCheckBox_Grades_Reports_Sex_Male)    
      sString = sString + " WHERE GradeSex = " + Chr(34) +  "M" + Chr(34)
    ElseIf GetGadgetState(gCheckBox_Grades_Reports_Sex_Female)          
      sString = sString + " WHERE GradeSex = " + Chr(34) +  "F" + Chr(34)    
    Else
      MessageRequester("Grades Reports", "Invalid selection", #PB_MessageRequester_Ok)
      ProcedureReturn
    EndIf 
    
    If GetGadgetState(gOption_Grades_Reports_Order_GradeNumber)
       sString = sString + " ORDER BY GradeNumber"
     ElseIf GetGadgetState(gOption_Grades_Reports_Order_GradeName)
       sString = sString + " ORDER BY GradeName"       
    EndIf
    report\SetCurrentSubreportDataSource(#nxReport_SQLITEDATABASE, "LacStat.s3db"+Chr(10)+sString)        
    report\PreviewInNewWindow(0, 0, 800, 650, "Grades: Reports", #PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered, 0, $47420A, #nxReport_SHOWPRINTBUTTON|#nxReport_SHOWTHUMBNAILNAVIGATION|#nxReport_MAKEMODAL, #Gray, 120)
    report\Destroy()
  Else
    Debug "dud report"
  EndIf

   nxReport_RemoveTemporaryFiles() ;Just in case.  
  
EndProcedure  

DataSection
  label_ReportStart:
    IncludeBinary "Grades.nxr"
  label_ReportEnd:
EndDataSection
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Arctic reports (reporting system - Windows)

Post by srod »

You're welcome Neil.
I may look like a mule, but I'm not a complete ass.
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Arctic reports - Setting a Label Value from PB

Post by Neil »

Hi srod,

I am trying to set a label value for "#label_ReportOrder", but it doesn't update the report !!

Code: Select all

    If GetGadgetState(gOption_Grades_Reports_Order_GradeNumber)
      sString = sString + " ORDER BY GradeNumber"
      sReportOrder = "Grade Number"
     ElseIf GetGadgetState(gOption_Grades_Reports_Order_GradeName)
       sString = sString + " ORDER BY GradeName"       
       sReportOrder = "Grade Name"       
     EndIf
     sReportOrder = "Report Order: " + sReportOrder
     report\SetParameter("#label_ReportOrder", sReportOrder)                    
     report\SetCurrentSubreportDataSource(#nxReport_SQLITEDATABASE, "LacStat.s3db"+Chr(10)+sString)        
     report\PreviewInNewWindow(0, 0, 800, 650, "Grades: Reports", #PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered, 0, $47420A, #nxReport_SHOWPRINTBUTTON|#nxReport_SHOWTHUMBNAILNAVIGATION|#nxReport_MAKEMODAL, #Gray, 120)
     report\Destroy()
Pyrex

Image

Thanks
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Arctic reports (reporting system - Windows)

Post by srod »

Changing the ID does not change the text content. You need to alter the source for that. It's original source is set to match the original ID only when the label is first created.
I may look like a mule, but I'm not a complete ass.
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: Arctic reports - Setting a Label Value from PB

Post by Neil »

srod wrote:Changing the ID does not change the text content. You need to alter the source for that.
So just to confirm - Are you saying that I cannot alter the text value from PB??
This will be a real hassle as it means I will have to go back to separate reports for all my options.

I want to be able to set the headers for the different report options from within PB.

Is there any other way I can achieve this ??

Does a Field work any differently than a Label ??

Thanks,
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Arctic reports (reporting system - Windows)

Post by srod »

I am not saying that at all.

You can change any report-related property from PB.

Use the control\SetSource() method to change a label's text. Just have a look at some of our demo programs which create reports directly using code; you can see how to set the source and so on.

Anything you can do with Pyrex, you can do with PB code. Pyrex is written in PB and uses the nxReport core module.

You can change headers, footers... anything from PB code.

A field control allows you to enter an expression (by starting it's source text with an '=' symbol). A label just takes a literal text value.

**EDIT : ah, I see why you might be confused. When I said in my previous post that you need to change the source, I didn't mean your PB source as such, I meant that you have to alter the label control's source property as opposed to it's ID property! :) You can achieve this either through Pyrex or directly through PB code.
I may look like a mule, but I'm not a complete ass.
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: Arctic reports (reporting system - Windows)

Post by Neil »

srod wrote: Use the control\SetSource() method to change a label's text. Just have a look at some of our demo programs which create reports directly using code; you can see how to set the source and so on.
Hi srod,

Looking at the code examples, I can see where you change the source when creating a control.

Code: Select all

 If report\AddNewControlToCurrentSubreport("#label_1_5", @control1) = #nxReport_OKAY
            control1\SetType(#nxReport_LABEL)
            text$ = "Please see page 2 of this report for a detailed list of nxReport's features."
            control1\SetSource(text$)
I'm not sure of the syntax to use in my case.

If I try:

Code: Select all

  If nxReport_CatchReport(?label_ReportStart, ?label_ReportEnd - ?label_ReportStart, @report) = #nxReport_OKAY
    report\UseSubreport("Page1", 0)
    sString = "SELECT * FROM Configuration, Grades "
    If GetGadgetState(gCheckBox_Grades_Reports_Sex_Male) And GetGadgetState(gCheckBox_Grades_Reports_Sex_Female)      
    ElseIf GetGadgetState(gCheckBox_Grades_Reports_Sex_Male)    
      sString = sString + " WHERE GradeSex = " + Chr(34) +  "M" + Chr(34)
    ElseIf GetGadgetState(gCheckBox_Grades_Reports_Sex_Female)          
      sString = sString + " WHERE GradeSex = " + Chr(34) +  "F" + Chr(34)    
    Else
      MessageRequester("Grades Reports", "Invalid selection", #PB_MessageRequester_Ok)
      ProcedureReturn
    EndIf 
    
    If GetGadgetState(gOption_Grades_Reports_Order_GradeNumber)
      sString = sString + " ORDER BY GradeNumber"
      sReportOrder = "Grade Number"
     ElseIf GetGadgetState(gOption_Grades_Reports_Order_GradeName)
       sString = sString + " ORDER BY GradeName"       
       sReportOrder = "Grade Name"       
     EndIf
     sReportOrder = "Report Order: " + sReportOrder
     
     report\UseSection(#nxReport_PAGEHEADER)     
     report\GetControlByName("#label_ReportOrder",@report)

'-----------------------------------------
     report\SetSource(sReportOrder)                    
;-----------------------------------------

     report\SetCurrentSubreportDataSource(#nxReport_SQLITEDATABASE, "LacStat.s3db"+Chr(10)+sString)        
     report\PreviewInNewWindow(0, 0, 800, 650, "Grades: Reports", #PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered, 0, $47420A, #nxReport_SHOWPRINTBUTTON|#nxReport_SHOWTHUMBNAILNAVIGATION|#nxReport_MAKEMODAL, #Gray, 120)
     report\Destroy()
I get:

Image

Thanks
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Arctic reports (reporting system - Windows)

Post by srod »

No no no no... :)

Ah you haven't looked closely enough.

Your problem is here :

Code: Select all

report\GetControlByName("#label_ReportOrder",@report)
report\SetSource(sReportOrder)
The \GetControlByName() method places a nxReport_Control object into a given variable and so you need to define an appropriate variable to hold it.

Use something like :

Code: Select all

Define.nxReport_Control control
If report\GetControlByName("#label_ReportOrder",@control) = #nxReport_OKAY
  control\SetSource(sReportOrder)
EndIf
I may look like a mule, but I'm not a complete ass.
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: Arctic reports (reporting system - Windows)

Post by Neil »

srod wrote: Use something like :

Code: Select all

Define.nxReport_Control control
If report\GetControlByName("#label_ReportOrder",@control) = #nxReport_OKAY
  control\SetSource(sReportOrder)
EndIf
Hi srod,

Thanks for reply (and thanks for persevering with me !!)

ok

1. Using your code I get error "Variable already declared with different scope: control"

2. Comment out line:

Code: Select all

;     Define.nxReport_Control control
      If report\GetControlByName("#Label_ReportOrder",@control) = #nxReport_OKAY
        Debug control\SetSource(sReportOrder)
        control\SetSource(sReportOrder)
      EndIf 
Program compiles ok, but Debug reports "0" (and label not updated).

3. Try a different variable name:

Code: Select all

      Define.nxReport_Control newcontrol
      If report\GetControlByName("#Label_ReportOrder",@newcontrol) = #nxReport_OKAY
        Debug newcontrol\SetSource(sReportOrder)
        newcontrol\SetSource(sReportOrder)
      EndIf    
Program compiles ok but debug still outputs "0"

Thanks,

Neil
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Arctic reports (reporting system - Windows)

Post by srod »

Well, the scope issue is clearly a problem with your program - nothing to do with Arctic Reports. :)

A zero return means everything is ok. (#nxReport_OKAY).

Any changes will only be visible when you preview the report anew.

Other than that, all I can say is that it works fine here. I have just tested it and ...no problems.
I may look like a mule, but I'm not a complete ass.
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: Arctic reports (reporting system - Windows)

Post by Neil »

Hi srod

Oh dear - what can I say - most humble apologies.

I write applications at work and application problems get classed as either "OE" = Operator Error, or "PE" = Programmer Error.

I'm afraid I have to admit that this is a case of "OS" = Operator Stupidity !!
srod wrote:Well, the scope issue is clearly a problem with your program - nothing to do with Arctic Reports. :)
This is what originally set me off on the wrong course - I thought there was something wrong in my coding.
srod wrote: A zero return means everything is ok. (#nxReport_OKAY).
Unfortunately this was another incorrect assumption on my part - I assumed that a result of zero was a fail.
srod wrote: Other than that, all I can say is that it works fine here. I have just tested it and ...no problems.
It actually came to me just as i was drifting off to sleep - funny how the brain works !!.
My label actually has a bit of text at the start.
In Pyrex I have "Report Order: "
and in PB I set the value to either:
"Report Order : Name" or "Report Order: Number"
The problem was that the width of the label was not big enough to show the whole value, and so I was only seeing "Report Order: " !!!
Knowing that zero meant ok, and also that it was working for you, forced me to think of what might be happening apart from an error in the code.
Widen the label and voila - Label is changing in the report!!
I do have to comment out this line

Code: Select all

;     Define.nxReport_Control control
but otherwise code is as your post.

So very sorry for wasting your time!!

Thanks,

Neil
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Arctic reports (reporting system - Windows)

Post by srod »

:lol:

No worries fella. Arctic Reports is a complex beastie and can take some mastering, especially the nxReport core module.

There is the \GetTextExtents() report method which, although deprecated, can be used to determine a control's nominal width etc. It is not a very flexible method mind, \ GetMinControlTextHeight() is better, but only works for heights and is intended for automatic control anchoring (where a control's height can automatically expand to accommodate whatever text it is about to display).

You can also remove 'clipping' from an individual control and thus the text will not be confined to the control's bounding rectangle etc. Course this means that all the control's text will be shoved onto a single line.
I may look like a mule, but I'm not a complete ass.
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: Arctic reports (reporting system - Windows)

Post by Neil »

Hi srod,

Thanks for the extra advice. As you say - a very complex package, but understandable, as it does a lot of "stuff".
Also very logical once you get the hang of it - which is the main thing.

OK - for my next query.

I will have about 20 different reports that will all have the same header.

Is there a way that I only have to edit the header details once?

I know that I can copy a report and then edit it, but as you can imagine, for each instance, I fine-tune the header a bit.

One option I thought of is that is there a way to combine reports, i.e. to have one report file for the Header and one report file for the Body.

The other option, which I did actually mention before, but for another reason, is if it would be possible for you to add an option to "Save To"/"Restore From" a text file, such the user could cut and past common report details.

Thanks again,

Neil
Post Reply