View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Make an Array 2-dimensional in VBA

The problem in the line
Total.NoMarkUpItems = Total.NoMarkUpItems + .aryPartQty(i) *
.aryPartDes(i)(1, 4)

because .aryPartDes(i) contains a single-dimensional array (created
with the Array function), and therefore you can't use the (1,4).
Choose either item 1 or 4 whichever is relevant. E.g,.

Total.NoMarkUpItems = Total.NoMarkUpItems + .aryPartQty(i) *
.aryPartDes(i)(1)

'or
Total.NoMarkUpItems = Total.NoMarkUpItems + .aryPartQty(i) *
.aryPartDes(i)(4)

Using a stripped out version of you code, the Locals window properly
reports
..aryPartDes(35)(3) = what should be there

It does not display as
..aryPartDes(35)(1,3)

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Wed, 10 Dec 2008 12:49:01 -0800, RyanH
wrote:

Understand that part, but what about my original question? In the code below
aryPartDes(36) and aryPartDes(37) look like this in the Locals Window:
aryPartDes(36)(1,1), aryPartDes(36)(1,2), aryPartDes(36)(1,3),
aryPartDes(36)(1,4).

But aryPartDes(35) looks like this aryPartDes(36)(1), aryPartDes(36)(2),
aryPartDes(36)(3), aryPartDes(36)(4). Is it possible for me to define the (
aryPartDes(35) ) array indicated below with "" like a 2D Array like
aryPartDes(36) and (37)?

I need to do this so my For...Next Loop works properly below. I get an
Error Subscript Out of Range.

This is what I have:

' in standard module
Type Sign
aryPartDes(1 To 37) As Variant
aryPartQty(1 To 37) As Double
End Type

Sub Test()

Dim MySign As Sign

With MySign
' onsite service techinician, do not mark up
If chkServicePlan Then
.aryPartDes(35) = Array("", "Ad Tech On Site Service Techinician", "ea.", CDbl(tbxOnSiteServiceTechCost))

.aryPartQty(35) = 1
Else
.aryPartDes(35) = Empty
.aryPartQty(35) = 0
End If

' software, do mark up
.aryPartDes(36) = PartInfo("Software")
.aryPartQty(36) = 1

' freight charges for modules, do not mark up
.aryPartDes(37) = PartInfo("ModuleShipRate")
.aryPartQty(37) = .ModuleCount * Val(tbxQuantity)

' sum items not to be marked up
Total.NoMarkUpItems = 0
For i = 35 To UBound(.aryPartQty)
If .aryPartQty(i) 0 Then
ERROR Total.NoMarkUpItems = Total.NoMarkUpItems + .aryPartQty(i) *
.aryPartDes(i)(1, 4)
End If
Next i
End With

End Sub