PC Review


Reply
Thread Tools Rate Thread

Defining a Dyanmic Array in User Defined Type

 
 
CK
Guest
Posts: n/a
 
      10th Apr 2008
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.
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      10th Apr 2008
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.

 
Reply With Quote
 
CK
Guest
Posts: n/a
 
      10th Apr 2008
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.

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      10th Apr 2008
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 With Quote
 
CK
Guest
Posts: n/a
 
      11th Apr 2008
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type mismatch: array or user-defined type expected Naftas Microsoft Excel Programming 3 23rd Mar 2010 03:43 PM
Passing Array of User Defined Type to Form dunnerca Microsoft Excel Programming 4 23rd Dec 2007 09:22 PM
Type Mismatch: array or user defined type expected =?Utf-8?B?RXhjZWxNb25rZXk=?= Microsoft Excel Programming 4 6th Jul 2006 03:40 PM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Microsoft Excel Programming 1 31st Oct 2005 08:20 PM
Passing User Defined Type Array to Listbox PC Microsoft Excel Programming 2 1st Jun 2005 02:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:03 PM.