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

Array Variable problem

Status
Not open for further replies.

jcfowl

Programmer
Feb 15, 2002
29
0
0
US
I haven't really used variables so this is all new. For some reason the global array variable always sees element 1 as being "". I declare the variables in the page header and
put the Formula below in a separate Formula Field. Any suggestions are appreciated. CRYSTAL SYNTAX.

WhilePrintingRecords;
Global stringVar array Feed_Parts;
Global numberVar arrIndex;

IF {TblInventory.Type} = "Feed" THEN
(
IF Feed_Parts[1] = "" THEN
(
Feed_Parts[1] = {TblInventory.Part_Code};
Cstr(Ubound(Feed_Parts)) & " Feed and First Element"
)
ELSE
(
Redim Preserve Feed_Parts[Ubound(Feed_Parts) + 1];
Feed_Parts[Ubound(Feed_Parts)] := {TblInventory.Part_Code};
arrIndex := arrIndex + 1;
Cstr(Ubound(Feed_Parts)) & " Feed and Not First Element"
)
)
ELSE
Cstr(Ubound(Feed_Parts)) & " Not Feed"
 
Just to be more clear. It never adds elements to the array. It goes to the second IF statement but never changes the value of element 1 so the ELSE portion is not used. I declare the array in the page header with a 1 element upper boundry with a value of "".
 
The pageheader will reset it each page, you might want to use the report header, or a group header if appropriate.

Is this in a subreport, or being passed to one?

-k
 
Thanks for the suggestion. It is not being passed to a subreport. Even when placed in the report header elements are not being added to the array variable.... When I get rid of the If statement and just always Redim Preserve the array it works fine. It just doesn't like my second IF statement where it checks the value of the first element.
 
Also, if you repeat the group header on the top of every page, you can still fall into the reset trap synapsevampire mentioned. To avoid this, preface your reset formula wiht the statement:

Not InRepeatedGroupHeader

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
dgilsdorf@trianglepartners.com
 
I almost have it.
Why does this work.........

WhilePrintingRecords;
Global stringVar array Feed_Parts;
Global numberVar arrIndex;

IF {TblInventory.Type} = "Feed" THEN
(
//IF Feed_Parts[1] = "" THEN
// (
// Feed_Parts[1] = {TblInventory.Part_Code};
// arrIndex := arrIndex + 1;
// Cstr(Ubound(Feed_Parts)) & " Feed and First Element"
// )
//ELSE
// (
Redim Preserve Feed_Parts[Ubound(Feed_Parts) + 1];
Feed_Parts[Ubound(Feed_Parts)] := {TblInventory.Part_Code};
arrIndex := arrIndex + 1;
Cstr(Ubound(Feed_Parts)) & " Feed and Not First Element"
// );
)
ELSE
Cstr(Ubound(Feed_Parts)) & " Not Feed"

__________________________________________________________
But this does not work........

WhilePrintingRecords;
Global stringVar array Feed_Parts;
Global numberVar arrIndex;

IF {TblInventory.Type} = "Feed" THEN
(
IF Feed_Parts[1] = "" THEN
(
Feed_Parts[1] = {TblInventory.Part_Code};
arrIndex := arrIndex + 1;
Cstr(Ubound(Feed_Parts)) & " Feed and First Element"
)
ELSE
(
Redim Preserve Feed_Parts[Ubound(Feed_Parts) + 1];
Feed_Parts[Ubound(Feed_Parts)] := {TblInventory.Part_Code};
arrIndex := arrIndex + 1;
Cstr(Ubound(Feed_Parts)) & " Feed and Not First Element"
);
)
ELSE
Cstr(Ubound(Feed_Parts)) & " Not Feed"
 
******
Thanks for the suggestion. It is not being passed to a subreport.
******

jcfowl - this statement caught my eye....You never said before that subreports were involved in this problem.

To pass values between a subreport and Main report you must have "Shared" variables....not Global Variables

Try this instead:

WhilePrintingRecords;
Shared stringVar array Feed_Parts;
Shared numberVar arrIndex;

IF {TblInventory.Type} = "Feed" THEN
(
IF Feed_Parts[1] = "" THEN
(
Feed_Parts[1] = {TblInventory.Part_Code};
arrIndex := arrIndex + 1;
Cstr(Ubound(Feed_Parts)) & " Feed and First Element"
)
ELSE
(
Redim Preserve Feed_Parts[Ubound(Feed_Parts) + 1];
Feed_Parts[Ubound(Feed_Parts)] := {TblInventory.Part_Code};
arrIndex := arrIndex + 1;
Cstr(Ubound(Feed_Parts)) & " Feed and Not First Element"
);
)
ELSE
Cstr(Ubound(Feed_Parts)) & " Not Feed"

Also in a similar manner make your other formulas that reference these variables "Shared" as well.

Hope this helps




Jim Broadbent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top