Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Member Login

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I just wanted to say THANKS for the forum. The knowledge I gain from your site is invaluable..."

Geography

Where in the world do Eng-Tips members come from?
BigInch (Petroleum)
1 Dec 10 13:59
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.

IDS (Civil/Environmental)
1 Dec 10 16:47
I just happen to have been reading about collections this morning in Professional Excel Development.  I'm not familiar with their use, but I think you need to create a collection of your UDT objects, and this collection will then have a count property.

This link might be useful:
http://www.cpearson.com/Excel/CollectionsAndDictionaries.htm

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

electricpete (Electrical)
2 Dec 10 7:42
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)'  ?

BigInch (Petroleum)
2 Dec 10 12:15
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.

BigInch (Petroleum)
2 Dec 10 12:37
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.  

IDS (Civil/Environmental)
2 Dec 10 15:22
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/
 

BigInch (Petroleum)
2 Dec 10 15:40
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

electricpete (Electrical)
2 Dec 10 16:33
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)'  ?

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!

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