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

Array with String as Index 1

Status
Not open for further replies.

cLFlaVA

Programmer
Jun 14, 2004
6,450
US
Hello.

I'm pretty new to Crystal. By pretty new I mean a couple of weeks.

I'm attempting to create an Array. Simple enough. I've looked through the help section on Arrays. I'm wondering if it's possible (I know it is in other languages) to create an array so I'll be able to reference the index by using a string.

For example:

array_name("cory") = 24
array_name("jane") = 32
array_name("harry") = 40

And then, display the value 24 by referencing array_name("cory").

Is this possible in Crystal? If not, is there any alternative solution?

Thanks.


*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
I don't think it is possible to do it hte simple way, but you can do it like this:

Code:
stringvar array arrNames := ["cory","jane","harry"];
stringvar strName := "jane";
numbervar x := 0;

if strName in arrNames then
    do (x := x + 1) while arrNames[x] <> strName;

x;

~Brian
 
Thanks.

So, let me give you some more detail on what I need to do, then maybe you can help me more! Fun!

I have set up a manual cross-tab that looks essentially like the following (simplified) sample:

[tt]
Apples Oranges Bananas
Team 1
Subgroup 1 2 3 6
Subgroup 2 0 4 3
Team 2
Subgroup 1 1 1 2
Team 3
Subgroup 1 5 6 2
Subgroup 2 0 1 0
Subgroup 3 2 2 2
[/tt]

What I'm eventually trying to get to is basically to display the % of Apples each team has in each subgroup. So, I'd want it to look like this:

[tt]
Apples Oranges Bananas
Team 1
Subgroup 1 [blue]25%[/blue] 30% 60%
Subgroup 2 0% 80% 100%
Team 2
Subgroup 1 [blue]12%[/blue] 10% 20%
Team 3
Subgroup 1 [blue]63%[/blue] 60% 20%
Subgroup 2 0% 20% 0%
Subgroup 3 100% 100% 100%
[/tt]

I blued one particular area in hopes it makes sense to all of you.

So, I know I have to store values in formulas, because % of column didn't come around until 9.0, and I'm using 8.5. This is why I wanted to store strings (subgroups) as indexes.

I don't simply want to show % of total column, but rather the % of total for that particular subgroup across all teams.

[red]THANKS A TON![/red]

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
I responded to your other post. Using your example here, I think your formulas should look like:

sum({@apples},{table.subgroup}) % sum({@apples})

//where {@apples} is a formula like:

if {table.fruit} = "apples" then {table.amount}

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top