×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

UDT collections

UDT collections

UDT collections

(OP)
It seems that a User defined type in VBA does not have a collections property.  Is this correct?  And if so, what is a good workaround for accessing the .count of a UDT array.

Replies continue below

Recommended for you

RE: UDT collections

Size can be found from array index limits which can be found with lbound and ubound...

CODE

Type mytype
  x As Double
  y As Double
End Type

Sub testtype()
 Dim myvar() As mytype
 ReDim myvar(3 To 9)
 Debug.Print "Size of myvar is " & UBound(myvar) - LBound(myvar) + 1
End Sub
Gives

Quote (output):

Size of myvar is 7
For multidimensional array lbound and ubound can take a 2nd argument to identify which index is being tested.

=====================================
(2B)+(2B)'  ?

RE: UDT collections

(OP)
EPete, Yes, I was familiar with the UL/bound statement, but what I was after was getting the number of items with somthing like myvar.Count and I couldn't get that to work.  It works in VB6 and it surprized me when it apparently didn't in VBA, since they are usually very similar.

I'll try IDS's suggestion, read up on it and figure out which will be the most convenient.

Thanks to both of you.

RE: UDT collections

(OP)
IDS,  I find UDTs very convenient to use in VB6.  I'm sure you'll get to like them.  You define an attribute of the type and its instantly available everywhere without all the bookkeeping of making a separate unconnected array of object attributes and keep indexing those to the original object array.  Very easy to add attributes "on the fly".  VBA UDTs seem to be composed of a smaller subset of functions than those available in VB6, that for some reason don't include the ".Count" functionality automatically, and I would imagine some others are missing that I haven't discovered yet as well.  

RE: UDT collections

BigInch - I think you are right, I could well find UDTs useful in situations where I currently tend to use arrays.  Many books gloss over Types as being a sort of second-class Class, and I have never really looked into them as a result.

I think my original response was misleading.  I was thinking of making a collection of instances of the Type, then that would have a .count property, but if you want a .count of the attributes of the Type itself, I don't know, and a search didn't find anything useful.  If I come across anything I'll let you know.

Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
 

RE: UDT collections

(OP)
I like using Types especially for program development where I tend to not have a well planned attribute list, for  example, I'll start with

Type FlowElement
     Diameter as ..
     Wall_Thickness as  ..
     Yield_Strength as ..
End Type

Then figure out I need to add FromNode, ToNode, Length, or CV coefficient or something, so I can do some newly thought out calculations I just discovered I need.  Really easy to just add them into the definition, define what they are in the sub and automatically keep each attribute indexed to its corresponding item in the FlowElement "array".

No. The article you gave me was good.  I never heard about the Dictionary thing before either!

Cheers^2

RE: UDT collections

There are two separate concepts:

One concept is array vs collection.  Collection has count property, array does not.

Another concept is is user defined data type vs other data types. It is entirely different distinction.   Either type could be used in array or collection.  The fact that an array doesn't' have a count property has nothing to do the fact that it is a user-defined data type. Arrays of double, Booleans etc also have no count property.

Maybe this is already understood by all... I'm not sure. If it is understood, then please feel free to ignore my comments.
 

=====================================
(2B)+(2B)'  ?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close