PDA

View Full Version : Solved: Combining Arrays



Djblois
05-14-2007, 12:08 PM
I am using Arrays to install certain features for certain individuals (they always install but they don't get access to certain features.) In certain instances I want to do the same thing to multiple Arrays, so I join the Array's into another array but from that point I can't get it to work.

Dim Accounting As Variant, Cheese As Variant, Developer As Variant, Grocery As Variant
Dim Meat As Variant, Retail As Variant, SalesPerson As Variant, Traffic As Variant
Dim AccountingReports As Variant, InventoryReports As Variant, SalesReports As Variant
Dim SalesPersonReports As Variant

Accounting = Array("tignat")
Cheese = Array("aberti", "cfranco", "irasnow", "mmazzella", _
"rmapelli", "vmiller")
Developer = Array("Dblois")
Grocery = Array("khausser", "mbarrios", "smylod", "tignat")
Meat = Array("")
SalesPerson = Array("cfranco", "csotolongo", "Cwrubleski", _
"eherrera", "gtatum", "jgarcia", _
"mcampion", "mjames", "mmazzella", "skaufman")
Retail = Array("csotolongo")
Traffic = Array("")

AccountingReports = Array(Array(Accounting, Developer))
InventoryReports = Array(Cheese, Developer, Grocery, Meat)
SalesReports = Array(Array(Cheese, Developer, Grocery, Meat, SalesPerson))
SalesPersonReports = Array(Array(Developer, SalesPerson))

'On the next line I get a type Mismatch error
If Not IsError(Application.Match(Environ("username"), SalesReports, 0)) Then
addSalesDetailReports
End If

Djblois
05-14-2007, 12:31 PM
one minor change:

AccountingReports = Array(Accounting, Developer)
InventoryReports = Array(Cheese, Developer, Grocery, Meat)
SalesReports = Array(Cheese, Developer, Grocery, Meat, SalesPerson)
SalesPersonReports = Array(Developer, SalesPerson)


However is still doesn't work. Also, when I set up a watch it does fill with the names. So that isn't the problem.

Bob Phillips
05-14-2007, 12:41 PM
You are building arrays of arrays, not combining them, so you have to address every level.

Djblois
05-14-2007, 12:43 PM
what do you mean address every level? I don't understand

Djblois
05-14-2007, 12:54 PM
I figured that so i tried this also:

If Not IsError(Application.Match(Environ("username"), Array(SalesReports), 0)) Then
addSalesDetailReports
End If

and


If Not IsError(Application.Match(Environ("username"), SalesReports(Array), 0)) Then
addSalesDetailReports
End If


and neither worked

and this one gives me subscript out of range:

If Not IsError(Application.Match(Environ("username"), SalesReports(), 0)) Then
addSalesDetailReports
End If

Bob Phillips
05-14-2007, 01:29 PM
I mean that it is like folders, there are arrays within arrays, all with different counts. Match will not work on these, that only works on single dimension arrays. So you either join the arrays, element by element, or you find another way.

Djblois
05-14-2007, 01:32 PM
Xld,

Is this what you mean by Join the Arrays, element by element?

InventoryReports = Array("aberti", "cfranco", "irasnow", "mmazzella", _
"rmapelli", "vmiller", "khausser", "mbarrios", "smylod", "skaufman", "tignat", "Dblois")
SalesReports = Array("aberti", "cfranco", "irasnow", "mmazzella", _
"rmapelli", "vmiller", "khausser", "mbarrios", "smylod", "skaufman", "tignat", "csotolongo", "Cwrubleski", _
"eherrera", "gtatum", "jgarcia", "lwarner", _
"mcampion", "mjames", "Dblois")
SalesPersonReports = Array("Dblois", "cfranco", "csotolongo", "Cwrubleski", _
"eherrera", "gtatum", "jgarcia", "lwarner", _
"mcampion", "mjames", "mmazzella", "skaufman")

Bob Phillips
05-14-2007, 02:01 PM
No, what I mean is like this.



Dim Accounting As Variant, Cheese As Variant, Developer As Variant, Grocery As Variant
Dim Meat As Variant, Retail As Variant, SalesPerson As Variant, Traffic As Variant
Dim AccountingReports As Variant, InventoryReports As Variant, SalesReports As Variant
Dim SalesPersonReports As Variant
Dim i As Long, j As Long, arySize As Long

Accounting = Array("tignat")
Cheese = Array("aberti", "cfranco", "irasnow", "mmazzella", _
"rmapelli", "vmiller")
Developer = Array("Dblois")
Grocery = Array("khausser", "mbarrios", "smylod", "tignat")
Meat = Array("")
SalesPerson = Array("cfranco", "csotolongo", "Cwrubleski", _
"eherrera", "gtatum", "jgarcia", _
"mcampion", "mjames", "mmazzella", "skaufman")
Retail = Array("csotolongo")
Traffic = Array("")

j = 0
arySize = UBound(Accounting) - LBound(Accounting) + 1 _
+ UBound(Developer) - LBound(Developer) + 1
ReDim AccountingReports(0 To arySize - 1)
For i = LBound(Accounting) To UBound(Accounting)
AccountingReports(j) = Accounting(i)
j = j + 1
Next i
For i = LBound(Developer) To UBound(Developer)
AccountingReports(j) = Developer(i)
j = j + 1
Next i

j = 0
arySize = UBound(Cheese) - LBound(Cheese) + 1 _
+ UBound(Developer) - LBound(Developer) + 1 _
+ UBound(Grocery) - LBound(Grocery) + 1 _
+ UBound(Meat) - LBound(Meat) + 1
ReDim InventoryReports(0 To arySize - 1)
For i = LBound(Cheese) To UBound(Cheese)
InventoryReports(j) = Cheese(i)
j = j + 1
Next i
For i = LBound(Developer) To UBound(Developer)
InventoryReports(j) = Developer(i)
j = j + 1
Next i
For i = LBound(Grocery) To UBound(Grocery)
InventoryReports(j) = Grocery(i)
j = j + 1
Next i
For i = LBound(Meat) To UBound(Meat)
InventoryReports(j) = Meat(i)
j = j + 1
Next i

j = 0
arySize = UBound(Cheese) - LBound(Cheese) + 1 _
+ UBound(Developer) - LBound(Developer) + 1 _
+ UBound(Grocery) - LBound(Grocery) + 1 _
+ UBound(Meat) - LBound(Meat) + 1 _
+ UBound(SalesPerson) - LBound(SalesPerson) + 1
ReDim InventoryReports(0 To arySize - 1)
For i = LBound(Cheese) To UBound(Cheese)
InventoryReports(j) = Cheese(i)
j = j + 1
Next i
For i = LBound(Developer) To UBound(Developer)
InventoryReports(j) = Developer(i)
j = j + 1
Next i
For i = LBound(Grocery) To UBound(Grocery)
InventoryReports(j) = Grocery(i)
j = j + 1
Next i
For i = LBound(Meat) To UBound(Meat)
InventoryReports(j) = Meat(i)
j = j + 1
Next i
For i = LBound(SalesPerson) To UBound(SalesPerson)
InventoryReports(j) = SalesPerson(i)
j = j + 1
Next i

j = 0
arySize = UBound(Developer) - LBound(Developer) + 1 _
+ UBound(SalesPerson) - LBound(SalesPerson) + 1
ReDim SalesPersonReports(0 To arySize - 1)
For i = LBound(Developer) To UBound(Developer)
SalesPersonReports(j) = Developer(i)
j = j + 1
Next i
For i = LBound(SalesPerson) To UBound(SalesPerson)
SalesPersonReports(j) = SalesPerson(i)
j = j + 1
Next i

'On the next line I get a type Mismatch error
If Not IsError(Application.Match(Environ("username"), SalesReports, 0)) Then
' addSalesDetailReports
End If

Djblois
05-15-2007, 07:23 AM
That works perfectly