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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global Variables 1

Status
Not open for further replies.

PhilipOfOrange

Programmer
Dec 28, 2000
19
US
I need to count the number of records processed in the detail band. I am assuming I need a global variable to do this, in order to retain the previous count for each pass through the band. In most programming environments you would not declare a global variable here, as it will be re-declared with each pass, raising big questions about what happens to the previous contents. Crystal does not seem to provide a way of testing for the existence of the variable before declaring it.

Global variables seem to be new with version 8. Hopefully there are a few people out there that have encountered and solved this problem.

Thanks for your help.

Phil
 
Crystal variables are a bit different than most other programming environments. You have to declare a "global" variable at the beginning of every formula that uses it, which makes the name "global" a bit confusing. Global in CR means that different formulas have access to that value.
Actually, all variables up through V7 were global in CR terms. What is new is that you can now have local and shared variables in V8.

Back to your immediate need. Please restate the question, since each detail band (that prints) 'processes' only one record from the results.

If you want a running count, use the running total feature of CR 8 and use the operation "count". Ken Hamady
Crystal Reports Training and a
Quick Reference Guide to VB/Crystal
 
I am creating a report to print invoices on preprinted forms. Our normal invoice is done in Crystal for use with blank paper. I am doing a custom for a customer that can't use the normal one. A few days ago (12/28)I posted to this forum and asked for help on how to control the size of the detail band, so that I could print the sub-total, tax and total in the pre-printed boxes. I received some good suggestions from dcm and MalcomW. I also found a post from
a woman working with pre-printed medical billing forms (thread 149-9294)on this forum on April 10, 2000. MalcolmW responded to that one also. Between the three responses I have figured out what I want to do, which is as follows.

Each item listed on the invoice will be pulled from a separate record in the item file and printed in the details section. In that section, I will check the "New Page Before" box and enter a formula that will count the number of items printed and force the page break when I run out of space. When I run out of items, I will print the report footer ("Print at Bottom of Page" checked) where the
"sub-total", "tax" and "total" printing are controlled.

Does this sound workable? The global variable that keeps track of the number of line items printed is what concerns me. It seems to me that this code gets evaluated after every line is printed and you keep re-declaring the variable. Maybe Crystal has built in logic to prevent this.

A sample report that did something like this would be very helpful, if someone could steer me to it.

I am using Crystal 8,
when distributed, the report will be printed using the
Crystal VCL (Visual Component Library)for Delphi




 
A variable gets evaluated based on where it is placed. Therefore, a formula that is placed in the details will fire every record, Placed in the in the Group header, once per group at the beginning, etc.

If you look at the FAQ on running totals, and check the "3 formula" option, I think you will get an example of how to increment and reset a variable. Ken Hamady
Crystal Reports Training and a
Quick Reference Guide to VB/Crystal
 

Sorry, I don't think I made myself clear. The example I am looking for, would be one that prints a report on pre-printed forms, not one that demonstrates the use of a variable. For instance, using a report header, a fixed height detail band and a report footer that is fixed to the bottom of the page.

In this instance, I have a pre-printed invoice form. In the HEADER will go the customer name, address, invoice number & date. In the DETAIL section I will list the items that were purchased. On each line will be an "item" which consists of the number of the UPC code that was scanned, a description of the item, the unit price, the quantity purchased, and the extended price (quantity * unit price). The form has room for about twenty single spaced items. In the REPORT FOOTER I must print the sub-total, tax, etc. in little boxes printed on the form. So I must control the detail section so that I go to a new page without totaling, every time I print 20 items in the detail band and still have more items to print.

In order to control the number of lines in the detail section, I want to use a numberVar in the “Page Break before” section of the detail band as a counter. I will increment the counter, every time I make a pass through the detail section, but if I understand you correctly, this won’t work, because I will evaluate all the code with every pass, which will cause the counter variable to be re-declared (even if it was declared globally and already exists) and that will reset the counter to zero. Doubtless, I am missing something here and rather than experiment and find something that usually works, until my customer tries it (whereupon it will immediately break) I thought perhaps someone could suggest an approach that they know will work. Feel free to assume I am dense and show me what code I need and where to put it to make this work.

Thank you for your patience.

Phil
 
I think the part you are missing is that in CR, redeclaring the variable doesn't reset it, just makes it availble to more than one formula.

Ken Hamady
Crystal Reports Training and a
Quick Reference Guide to VB/Crystal
 
Ken,

Thanks for your help. I found a way to avoid using variables altogether.

In the detail band, I used the following:

Remainder(RecordNumber,20)=0,

Which will only allow 20 records in the detail band. Therefore a fixed length detail band. Unfortunately, I would like to allow "can grow" on a description field but I can't figure out how to control the number of lines without it getting pretty messy. I will look again at using variables for this when I have more time to experiment.

I appreciate your sticking with me on this. At the very least you stimulated my thinking and gave me some insight into how Crystal handles variables.

Phil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top