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

? concerning running two seperate formulas

Status
Not open for further replies.

espltd

Programmer
Apr 6, 2005
233
US
Hi just wondering if anyone knows if it is possible to run two formulas formula 1 first and formula 2 second, and have formula 1 save data to an array-not write anything to the report, and have formula 2 use the data from formula 1 and then write data to a report? If so any example crystal syntax. Also is there a previous function using vb syntax as I could not find it.
thanks
 
You can do this. It's a little tricky but not too bad.

The trick with this is in how crystal times operations. You have to get your array filled before you do anything with it display wise.

You can build a report with a subreport in the footer. The main report has all your data operations that fill the array. The subreport does any remaining work. You suppress the majority of the main report and have the subreport do the display as if it were the main report.

The reason for this is that crystal will perform operations on the main report first, and then it will work on the subreport. You are fooling crystal into doing all the array construction before it shows anything.

Your array has to be a shared variable or it won't go to the subreport.

shared numbervar array arrLastYrYTD01;

You have to redim it:

shared numbervar maxarraysize:=1000;
redim arrLastYrYTD01[maxarraysize];


You may have to initialize the values with a do loop or for-next

for x:=1 to maxarraysize
Do
(
arrLastYrYTD01[x]:=1;
...etc.


Obviously that isn't always going to be necessary.

Then you fill the array with values:

shared numbervar array arrLastYrYTD01;
shared numbervar maxarraysize;
numbervar counter;
local numbervar numValue:=(Sum ({@numTaxPdLastYearYTD}, {@Groups01License}));

if numValue=0 then
0
else (
select counter
Case 1 to 1000:
arrLastYrYTD01[counter]:=numValue

...etc.


You increment your counter at the end of this so that it advances with each record. You can do it inside the same formula.

Then you set up your subreport to look like a main report, you have to initialize the array there as well, redim preserve

redim preserve arrLastYrYTD01[maxarraysize];

I'm not 100% sure that last step is necessary but I'm going to leave it in my code.

Then you should have an array that your subreport can work with to it's heart's content.

In this example, I had to find the rank of a set of things according to three different columns and display all three ranks. I got around the 1000 point limit in the arrays with 10 arrays and some if-then logic to deposit the values into the correct array using the counter. Then I used a for-next loop to compare each given value to all the others in the array (asking if the item was greater than or equal to and then incrementing a counter if it was).

Anyway, that's an example that worked pretty well. Let me know if you need to see the complete code. I kept it brief here for readability.

Scott.
 
Hi Scott thanks for the information. I will take a look at it. I have not worked with subreports but looks sounds like a good idea. I also found EvaluateAfter (x)which forces 1 formula to be evaluated after another. Here is what I have so far,
in the first formula, just to fill an array

Global data (1) as String
Global i as Number
i=1
if (({table1.field1} = PreviousValue({dml_get_searchlog.Data_Item_Log_ID})or({dml_get_searchlog.Data_Item_Log_ID}) <> PreviousValue({dml_get_searchlog.Data_Item_Log_ID}))) then
data(i)=ToText(Cstr({table1.field1},"000000"))
redim data(i+1)
i=i+1
end if
formula = data(i)
I have the if statement only to fill the data, not sure if it is needed or not.
What I am trying to do is add -0x to numbers like follows
from dbase I have
1
2
2
3
4
4
4
and need to display
000001-01
000002-02
000002-01
000003-03
000004-03
000004-02
000004-01
so seems like I could fill an array first with 1 formula and then with the second go through the array and if the number is repeated 3 times just add -03 to the first one, decrement and add -02 to the next and so on.
thanks again.
 
I think I may have to use the subreport method described as I tried calling one function after the first one, this works but since the second function is called after each record is read in the entire array is not filled yet.
record 1 function 1 function 2
record 2 function 1 function 2
function 2 fills array, function 1 uses array to get # of like values and add the -03,-02-01, etc, depending on the number of like values.
 
Please see my response to your other post (thread767-1115020). It would have been better to keep this as one thread.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top