cancel
Showing results for 
Search instead for 
Did you mean: 

Upgrading specific abilities from VB6

0 Kudos

In visual basic 6 the Format event of specific sections is used to run code to achieve out desired functionality, however, I am having difficulty figuring out how to do this in .NET.

I currently have Crystal Reports for Visual Studio installed and patched to SP9.

Specifically what was done is the following:

We retrieved the current page number being sent to the printer using the Report's BeforeFormatPage event (I think we can still do this)

We then retrieved a value from the section being printed and used it to update data in the database.  We only want the data updated if the page that contains that data is actually sent to the printer.  In one case this is being used for cheque reports as the client wants to track which actual cheques were printed, not those that were displayed in the crystal preview window, to ensure that the cheque number that was printed matches that which is stored in the database.

In another case the format event is used to load a picture into a report object.  Note that the code supports multiple types including png, tif, ico, or wmf.  It also makes an attempt to proportionally size the image to fit on the report.

I believe in some cases it resized the control on the report to prevent distortion of the image.

I see that the report has a FormatSection event, but I am unsure how to use the sectioncode to find the sectionobject being formatted.  I also wonder if this will happen when the specific pages of the document are sent to the printer so as to achieve the same effect we did in VB6.

I appreciate your assistance with this.

Thank you,

Shaggie

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

I forgot to mention a few other things that the code in VB6 does.

  1. Formulas are updated based on client actions.  In one case a formula is used to display the client's company name.  We have found this to be significantly faster than a subreport that retrieves this data.

  2. Under certain circumstances, a label is injected into the report with the word "Draft".  This is done to prevent client's from using our software without paying the licensing fees.  That label does not exist in the actual report file.

  3. The code reads the total actual # of pages in the report for looping and recording purposes.

  4. Some custom reports were created in Crystal 8 (and perhaps even v7) and have not been upgraded.  I mention this because I wonder if the code can use features of crystal report objects that did not exist in the older versions when displaying and printing the reports using the newer versions.
0 Kudos

Hi Shaggie,

There are limits to what the new .NET Windows form viewer has for Event triggers.

In VS click on the viewer on the form and the lightening bolt to get the list.

These are all that are available.

If there are some specific ones you need let me know and I'll ask if it's possible to add them.

Don

0 Kudos

Yes, I figured as much.  The VB6 RDC viewer has limits as well which is why events against the report itself were used such as the Section_Format event.  They were able to be wired up by declaring a section object "WithEvents" and set that new object to the actual section in the report that we needed this event for.  Thankfully it fired when sending each page to the printer so we achieved the desired results - each instance of the section would cause the event to be fired.

I am just not sure how to do this with .NET.  I see that there is a FormatSection event, but I do not know how to find the exact instance of the section being formatted (essentially like Section X on Page Y - however that may not be valid as there may be no forced page breaks so a section may appear multiple times on a page) as the only thing that event seems to provide in that regard is the SectionCode.

A property such as ActiveSection would do the required job as long as the event is fired for each section instance.  If it isn't, then we would need another way to accomplish this.  An event on a report object instance could work as well in place of one on the section instance since really what is needed is to read the value, but that probably would not work for loading images.

I also could find no indication as to when the FormatSection event would be fired (hopefully just like the VB6 event where it would fire both on view and on print if it works like we need it to).

If Crystal reports can handle loading all of the image types specified previously as well as bmp and jpg files, can have formulas for sizing, and can allow for sizing proportionally such as by providing the image's original size (this is what the VB6 code does) for use in formulas (the VB6 code does the resizing as well) then potentially the loading and sizing could be handled within the report itself.  If not then it would need to be done via code like it is in VB6.  Not all images are done like that, just some of them.

Like I said before I am also concerned about whether setting or using these new properties programmatically would work with old report files.

Also I have not yet figured out how to do the rest of that functionality I mentioned previously.

I am not sure what else to say about them, but please feel free to ask any questions you feel necessary.

Thank you again,

Seradex

DellSC
Active Contributor
0 Kudos

There are MAJOR differences in the underlying structure of the .rpt file starting with Crystal 9.  Although it's possible to view older reports in the viewer that doesn't completely guarantee that the newer SDK will work with them.

Also, in Crystal 8 and earlier you could directly modify the SQL that Crystal generated.  Reports where this was done will NOT work with the new SDK.  They have to be completely rewritten using a Command (SQL Select Statement.)  For example, in 2006 I spent a couple of weeks updating @150 reports to move from Seagate Info 7.5 to BusinessObjects XI r2 because we had modified the SQL to take the db owner name prefix off of the table names (Oracle database) to make it easier to move them between environments.  Even something as simple a that cause the reports to lose the links between tables and do Cartesian joins instead of showing the correct data.

-Dell

0 Kudos

I was thinking that might be an issue which is why I mentioned it.  Similar fun was had here when migrating from Crystal 7 to 8 and again to XI R2.

My concerns are more with my reports which would/should all be upgraded to the latest version.  I do know though that some clients have old reports that they may not have upgraded (pre Crystal 9) that they run using our code.

I was hoping that someone would either provide some code samples, or point me at the events/methods/properties that I should be using to satisfy my needs, or let me know that X cannot be done at this time in the current version, even if that is done with separate replies.

Seradex

0 Kudos

Well you could start off by listing the events you are using...

Don

0 Kudos

In Crystal Report XI R2 with VB6 I am using the following:

  • With the Report:
    • OpenSubreport method -> to access & control sub-reports - I think I have this one figured out.
    • FormulaFields property -> of reports to modify the formulas
    • BeforeFormatPage event -> to get the current page number being sent to the printer.
    • PrintingStatus property -> of the report object to read the following sub properties.
      • NumberOfRecordPrinted property
      • NumberOfRecordRead property
      • NumberOfPages property - first two are compared to ensure that this one is correct.
  • With a Section:
    • Format event -> for individual sections in the report.  Used to access report objects in this instance of the section.
    • BackColor property -> to change the section backcolor.
    • AddTextObject method -> this is to add "Draft Copy" to reports when not licensed to use them.
  • With a ReportObject
    • FormattedPicture property -> for ICROleObject objects which is IPictureDisp compatible.
    • TextColor property -> to change the reportobject textcolor.
  • With the CrystalActiveXReportViewer object.
    • GetCurrentPageNumber method -> To read the currently displayed page number.

There may be others that I use and have yet to determine how to do this in the new version, however these are the main ones beyond the normal things that I have already found the equivalents for.

I look forward to hearing from you.

Seradex

Answers (0)