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

How to access shared array in another formula HELP! 1

Status
Not open for further replies.

slim2

Programmer
Oct 18, 2001
94
I have an array
Shared numberVar array TotLnDol := [13];

I have defined it the same way in another formula to access it, but I do not get any values, I know there are values there. Is this correct? I can find no information in any if the manuals.

Thanks
 
You don't need an array if you are only assigning a single value. Also, if both formulas assign a value then neither will see the other's value.
Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
kenhamady,
Thanks for the reply.

Sorry for the short description. I am filling the array with values assigned based on month. e.g. for jan it is [1] for mar it is [3] etc.
Since there are various calculations I want to do it in this frmula and then in jan detail say e.g Amt[1] etc. then the appropriate value will print and if it was not that month it would be zero.

I hope that is clearer. I keep getting subscript value must be in range of array. I have printed the subscript value and it is correct.

I cannot get by the error and there is no info available anywhere.

Thanks

 
Please post the actual formulas. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Ken,

this is the first formula call it amt

Shared numberVar array TotLnDol := [0,0,0,0,0,0,0,0,0,0,0,0,0];
Shared numberVar array NonAcDol;
NumberVar I;
If Left({Tportf.LamtDate},4) < {@curyr} Then
I := 13
else
I := ToNumber(Right({Tportf.LamtDate},2));
//
If {Tportf.Status} = &quot;8&quot; Then
NonAcDol = {Tportf.Lamt}
Else
TotLnDol = {Tportf.Lamt};

Second formula Janprt

Shared numberVar array TotLnDol := [0,0,0,0,0,0,0,0,0,0,0,0,0];
TotLnDol[1]

printline has @Janprt

Thanks
 
Ken,
I have also tried this on the second formula. Still get zero.


Shared numberVar array TotLnDol;
Redim Preserve [13].
 
I think the problem is that you are resetting the array to zeros every time you declare it. You only need to Initialize the array once, at the beginning of the report. This should be in a non-recurring formula. From then on you just declare it and assign values to subscripted elements in the array. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Ken,

Thank you for the reply. I have tried your sugesstion, it made sense, however I made the change and now Crystal crashes everytime I try to run the report. i also set it back to the way it was and it still crashes. I will try to get the report to run again and go from there.
 
Ken,

This simple formula is the only one, for test ppurposes, on a detail report and I still cannot getCrystal to print a value. I have set the array position 1 to a value of 20 and placed the formula on the deatil line. It prints 0. If anyone can help tell me what I am doing wrong it would be graetly appreciated.

WhilePrintingRecords;
Global NumberVar Array TotLnDl := [0,0,0,0,0,0,0,0,0,0,0,0,0];
Local NumberVar x;
Redim Preserve TotLnDl[13];
x := Tonumber(Right({Tportf.LamtDate},2));
TotLnDl[1] = 20;
TotLnDl[1];
 
Try this.
Notice that I added a colon in the second to last line.

WhilePrintingRecords;
Global NumberVar Array TotLnDl := [0,0,0,0,0,0,0,0,0,0,0,0,0];
TotLnDl[1] := 20;
TotLnDl[1]; Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Ken,

Thank you for the help. The formula as you gave it to me worked fine. Also, when i created another formula to print the array field it printed fine. What I cannot get to work is when I use a field as a subscript value. Whenever I use a variable field, i.e. x, it will always show 0. I cannot understand what is happening. This is what I did with your example.

On the report header.. count shows 13

Global NumberVar Array TotLnDl := [0,0,0,0,0,0,0,0,0,0,0,0,0];
Count(TotLnDl)

The value for x is always between 1 - 12. I printed it prior to adding the code. The field Tprotf.Lamt is a currency field and contains data.


Global NumberVar Array TotLnDl;
NumberVar x;
//TotLnDl[1] := 20;
//TotLnDl[1];
//x
x := ToNumber(Right({Tportf.LamtDate},2));
TotLnDl[x] = {Tportf.Lamt};

This formula always shows 0 for whatever value is used for the subscript.


Global NumberVar Array TotLnDl;
TotLnDl[1];

Thanks, I appreciate your help.


 
Start all formulas with:

WhilePrintingRecords; Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Ken,
I have added WhilePrintingRecords; as the first line in each formula. I still get 0 for the formula shown as #3 above, no matter which subscript value I use. I did notice one thing, and don't know what it means, if I use

TotLnDl[x] := {Tportf.Lamt};
I get a number is required here and have to use just =.

But in your example using a integer value and := it does work with the [x] in the appropriate slot of the array. Fpr some reason TotLnDl[x] = {Tportf.Lamt}; will not populate??? but TotLnDl[x] := 20; will.

 
I am afraid that for me to troubleshoot this question further would require more effort than I can devote to a Tek-Tips thread. You might want to consider getting an expert to look at the report. There are several experts here (you can tell by looking at our signatures) who are also available for rent. Please make contact outside of TT, since recruiting is not allowed here.

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Ken,

I have gotton the following to work, and do not know why.
Adding the additional moves will cause the print to work.

NumberVar amt;
amt := ToNumber({Tportf.Lamt});
TotLnDl[x] := amt;


Thanks for all your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top