563 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Posted by Andrew Gould on 13 October 2014
The Type statement in VBA allows you to define your own static data structures which you can then use in your variable declarations. This video explains how to declare a type, how to employ the type in variable declarations, how to read to and write from the variable, as well as a couple of fun features such as using enumerations within a type declaration and nesting types.
There are no files which go with this video.
There are no exercises for this video.
You can increase the size of your video to make it fill the screen like this:
Play your video (the icons shown won't appear until you do), then click on the full screen icon which appears as shown above.
When you've finished viewing a video in full screen mode, just press the Esc key to return to normal view.
To improve the quality of a video, first click on the Settings icon:
Make sure yoiu're playing your video so that the icons shown above appear, then click on this gear icon.
Choose to change the video quality:
Click as above to change your video quality.
The higher the number you choose, the better will be your video quality (but the slower the connection speed):
Don't choose the HD option shown unless your connection speed is fast enough to support it!
Is your Wise Owl speaking too slowly (or too quickly)? You can also use the Settings menu above to change your playback speed.
|When:||18 Aug 19 at 14:33|
Love the way you teach and the videos, they are always my go to point and have allowed me to do some great things!
My question is on using User Defined Type Declarations with class modules (specifically property statements), I have a large number of private fields in my class module (SupplierASearchString, SupplierAWorksheet, SupplierBSearchString, SupplierBWorkSheet etc etc). I am thinking of trying to simplify this by using User Defined Types (UDT), thus allowing me to have a single Private Field per supplier declared using my UDT.
It would appear that you can not declare property statements for the individual elements of a UDT. Not all of my elements are set at the same moment in the procedures that i am running, would this mean that UDT are probably not the best approach or am i missing something fundimental with regards to UDTs?
Dave Blake MAAT
|When:||19 Aug 19 at 14:02|
You might it helpful to read this post first https://stackoverflow.com/questions/975982/user-defined-type-udt-as-parameter-in-public-sub-in-class-module-vb6
The TL;DR version is that you can't do what you're attempting. You could accomplish this using two different class modules. The first class module will simulate what your type does, call it SupplierType for example:
'SUPPLIER TYPE CLASS MODULE
Public SupplierASearchString As String
Public SupplierAWorksheet As String
Public SupplierBSearchString As String
Public SupplierBWorksheet As String
You can then use another class module which has a single property whose type is the SupplierType class. Call this class module SupplierClass for example:
'SUPPLIER CLASS MODULE
Private pSupplier As SupplierType
Private Sub Class_Initialize()
Set pSupplier = New SupplierType
Public Property Get Supplier() As SupplierType
Set Supplier = pSupplier
You can then create a regular module which has code similar to this:
Dim s As SupplierClass
Set s = New SupplierClass
s.Supplier.SupplierASearchString = "supplier A"
I hope that helps!
|When:||20 Aug 19 at 18:09|
Many thanks for your response, I don't really need property statements in my current project anyway as it doesn't require any fancy validation, so passing to (& reading from) the field will work fine and the benefits of making my project more readable outway the limitations!
I can see me using UDTs a lot in my projects going forward, especially when combined with enumerations.
PS: I would love to see a future video around the principles of structuring larger projects, I realise that every project is different but I still can't decide if it is best to have lots of short modules and classes or have fewer but longer modules and classes. I think I might have a look at the Flappy Owl blogs to see how you structure your projects.
|When:||21 Aug 19 at 07:55|
When it comes to structuring a project I think the length of the modules and classes is mostly determined by the complexity of the entity you're trying to model; form follows function. You'll find a combination of very short and quite long classes in the Flappy Owl example. In the interest of getting things done, my advice would be not to worry about it too much, too early (premature optimisation is the root of all evil). If you find that your classes become unwieldy, you can always refactor later.
|When:||28 Jun 19 at 10:10|
Hello, dear Andrew.
I do not understand what is a "correct order" in type declaration? The meaning of it avoids me for some reason.
|When:||01 Jul 19 at 09:42|
Hi Alexander, I'm not quite sure what you mean, is this something I mentioned in the video? If so please can you let me know where and I'll see if I can remember what I was talking about (this video was posted in 2014 so it's been a while!)
|When:||01 Jul 19 at 10:50|
Hi Andrew, in the video above "VBA - classes and structures videos | Excel VBA Part 34 - Type Declarations", (13min 27sec) you were saying about "The order of declarations" and what happens when I declare types in defferent order. You changed the order of declaration of Types (Address and Contact) and sub stoped work. And I wonder what that order of declaration should by.
Sorry for my stupidity
and thank you very much!
|When:||01 Jul 19 at 11:26|
Ok, I see what you mean! In the example shown in the video we declare the Address Type first, followed by the Contact Type. The Contact Type references the Address Type and so the Address Type must be declared first.
I hope that makes sense!
25 Aytoun Street