Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ck ck is offline
external usenet poster
 
Posts: 52
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
ck ck is offline
external usenet poster
 
Posts: 52
Default 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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #5   Report Post  
Posted to microsoft.public.excel.programming
ck ck is offline
external usenet poster
 
Posts: 52
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Array of User Defined Type to Form dunnerca Excel Programming 4 December 23rd 07 09:22 PM
rediming dynamic 2 dimensional array of user defined type Arnold Klapheck Excel Programming 2 September 21st 06 05:10 PM
Type Mismatch: array or user defined type expected ExcelMonkey Excel Programming 4 July 6th 06 03:40 PM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Passing User Defined Type Array to Listbox PC[_4_] Excel Programming 2 June 1st 05 02:44 AM


All times are GMT +1. The time now is 10:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"