Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 4031

Grouping data with arrays

$
0
0

I have 2 related arrays of data. I would like to list the sales, grouped by category id.
I can figure out how to group the categories on 3 lines, but I can’t determine how to group the sales with the categories. I’m thinking I have the wrong approach here. Any thoughts?

Var CategoryID() As String = Array("3", "1", "3", "2", "1", "2", "3", "2") 

Var Sales() As Double = Array(20.00, 10.00, 30.00, 25.00, 15.00, 10.00, 20.00, 8.00)  

CategoryID.SortWith(Sales)

Var LastCategory As String
Var CategorySales As Double

Var SalesByCategory() As Double
Var CategoryGroup() as String

For i as Integer = 0 to CategoryID.LastIndex
  if CategoryID(i) <> LastCategory then
    CategoryGroup.Add(CategoryID(i))
  end if
  LastCategory = CategoryID(i)
next

// Test Results
For i as Integer = 0 to CategoryGroup.LastIndex
  System.DebugLog "CategoryGroup = " + CategoryGroup(i)
next

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4031

Trending Articles