Print Page | Close Window

Arrays

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=2668
Printed Date: 28 Apr 2024 at 7:46pm


Topic: Arrays
Posted By: bobbabuoy
Subject: Arrays
Date Posted: 21 Mar 2008 at 4:00am
I am a vb/asp programmer that is trying to learn CR.  I want to declare a 1-dimensional array and assign it values in the selection formula area.  Can someone give me the Crystal Syntax for this?

Thanks~



Replies:
Posted By: BrianBischof
Date Posted: 21 Mar 2008 at 2:51pm
Here is a quick sample code that should be enough to get you going.
NumberVar Array X;
ReDim X[2];
X[1]:=1;
X[2]:=55;

I cover arrays and the functions for working with them in Chapter 7 of my Crystal Reports Encyclopedia book. You can find out more about my books at http://www.amazon.com/exec/obidos/ASIN/0974953601/bischofsystem-20 - Amazon.com or reading the http://members.crystalreportsbook.com - Crystal Reports eBooks online.

And did you really post this question at 4am??


-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: bobbabuoy
Date Posted: 22 Mar 2008 at 5:50am
Thanks for the help.  I am new to CR as I said but this looks like a great resource.  I expect to be buying your book. 

Here is my next question:  I have this selection code:

StringVar Array AccntNum;

ReDim AccntNum[11];

AccntNum[1]:="000";
AccntNum[2]:="00";
AccntNum[3]:="01";
AccntNum[4]:="02";
AccntNum[5]:="03";
AccntNum[6]:="04";
AccntNum[7]:="05";
AccntNum[8]:="08";
AccntNum[9]:="11";
AccntNum[10]:="12";
AccntNum[11]:="13";

if {?AccntNum} <> "" then
    {Orders.Account #}={?AccntNum} and {Orders.Use Date} = {?DateRange}
else
  {Orders.Use Date} = {?DateRange}


I want to exclude the account numbers in the AccntNum array from selection.  How can I do that?



Posted By: BrianBischof
Date Posted: 22 Mar 2008 at 9:18am
Can you rephrase the question? Are you trying to exclude records that have an acctnum in the array from being printed, or are you trying to redo the if-then statement to make it use the array. Not sure what the exact problem is...

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: bobbabuoy
Date Posted: 22 Mar 2008 at 11:03am
I am trying to exclude records from the database that meet a certain criteria (those that have an account number that is included in the array) from being displayed.  


Posted By: bobbabuoy
Date Posted: 25 Mar 2008 at 4:06am
Totally rephrasing the question here:

Here is what I have and it works fine but it seems a little too "brute force".  Also, it begs the larger question:  How do I exclude records from the sql query based on their value (as I am doing here with these 11 values) without listing each one out?


if {?AccntNum} <> "" then
    {Orders.Account #}={?AccntNum} and {Orders.Use Date} = {?DateRange}
else
    if {Accounts.Account #} <> "000" and {Accounts.Account #} <> "00" and {Accounts.Account #} <> "01" and {Accounts.Account #} <> "02"
    and {Accounts.Account #} <> "03" and {Accounts.Account #} <> "04" and {Accounts.Account #} <> "05" and {Accounts.Account #} <> "08"
    and {Accounts.Account #} <> "11" and {Accounts.Account #} <> "12" and {Accounts.Account #} <> "13" then
        {Orders.Use Date} = {?DateRange}


Thanks in advance...


Posted By: Urgh
Date Posted: 25 Mar 2008 at 3:45pm
Use the select expert to select the account number then "not one of" then key in the account numbers you want to exclude.


Posted By: bobbabuoy
Date Posted: 25 Mar 2008 at 4:01pm
The problem with that is that I have a "Composite Expression" and I am told, "Please use the formula editing to do editing.


Posted By: BrianBischof
Date Posted: 25 Mar 2008 at 7:23pm
Rather than having CR create the formula, enter it manually using the formula editor. I would replace the else section with something a bit more elegant using the IN operator and an array constant.
....
else
    if NOT ({Accounts.Account#} IN ["000","00","01","02"]) then
       {order.use date} = {?DateRange}

Of course, add all the string tests rather than just the few I copied.

Chapter 7 of my book covers how to use arrays and the functions that work with arrays. You can find out more about my books at http://www.amazon.com/exec/obidos/ASIN/0974953601/bischofsystem-20 - Amazon.com or reading the http://members.crystalreportsbook.com - Crystal Reports eBooks online.

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>



Print Page | Close Window