Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
How would you define a dynamic array in a UDT? For instance, how could I do
something like: Type InventoryList nItems As Long inventory(1 to nItems) As Long End Type Cheers. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dim inventory() As Long
Dim nItems As Long nItems = 6 ReDim inventory(1 To nItems) As Long -- Gary''s Student - gsnu200778 "CK" wrote: How would you define a dynamic array in a UDT? For instance, how could I do something like: Type InventoryList nItems As Long inventory(1 to nItems) As Long End Type Cheers. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for your suggestion but this is not a user defined type.
"Gary''s Student" wrote: Dim inventory() As Long Dim nItems As Long nItems = 6 ReDim inventory(1 To nItems) As Long -- Gary''s Student - gsnu200778 "CK" wrote: How would you define a dynamic array in a UDT? For instance, how could I do something like: Type InventoryList nItems As Long inventory(1 to nItems) As Long End Type Cheers. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'd use:
Option Explicit Type InventoryList nItems As Long Inventory() As Long End Type Sub aaa() Dim myInventory(1 To 3) As InventoryList Dim iCtr As Long Dim nCtr As Long For iCtr = LBound(myInventory) To UBound(myInventory) myInventory(iCtr).nItems = 3 ReDim myInventory(iCtr).Inventory(1 To myInventory(iCtr).nItems) 'put some values in For nCtr = 1 To myInventory(iCtr).nItems myInventory(iCtr).Inventory(nCtr) = 2 * nCtr Next nCtr Next iCtr End Sub CK wrote: How would you define a dynamic array in a UDT? For instance, how could I do something like: Type InventoryList nItems As Long inventory(1 to nItems) As Long End Type Cheers. -- Dave Peterson |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This is what I did on my laptop (Excel 2007) last night but it wouldn't work.
When I try the same thing this morning on my work PC (Excel 2003) then it works. Let me re-try it on my laptop tonight to see. Thanks Dave for your solution. "Dave Peterson" wrote: I'd use: Option Explicit Type InventoryList nItems As Long Inventory() As Long End Type Sub aaa() Dim myInventory(1 To 3) As InventoryList Dim iCtr As Long Dim nCtr As Long For iCtr = LBound(myInventory) To UBound(myInventory) myInventory(iCtr).nItems = 3 ReDim myInventory(iCtr).Inventory(1 To myInventory(iCtr).nItems) 'put some values in For nCtr = 1 To myInventory(iCtr).nItems myInventory(iCtr).Inventory(nCtr) = 2 * nCtr Next nCtr Next iCtr End Sub CK wrote: How would you define a dynamic array in a UDT? For instance, how could I do something like: Type InventoryList nItems As Long inventory(1 to nItems) As Long End Type Cheers. -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Passing Array of User Defined Type to Form | Excel Programming | |||
rediming dynamic 2 dimensional array of user defined type | Excel Programming | |||
Type Mismatch: array or user defined type expected | Excel Programming | |||
Help: Compile error: type mismatch: array or user defined type expected | Excel Programming | |||
Passing User Defined Type Array to Listbox | Excel Programming |