![]() |
Defining a Dyanmic Array in User Defined Type
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. |
Defining a Dyanmic Array in User Defined Type
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. |
Defining a Dyanmic Array in User Defined Type
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. |
Defining a Dyanmic Array in User Defined Type
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 |
Defining a Dyanmic Array in User Defined Type
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 |
All times are GMT +1. The time now is 12:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com