Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
Now I want to take a look at using this class to create an object, and I want you to see exactly what happens. This is my class from here down to here, and notice my class has a couple of variables that we can set, properties they will become. And notice we have these particular sub-routines inside here. And to create a new object off of Mark, I'm going to use the term Dim for setting it up or dimensioning a portion of memory for this, and I'm going to call it 'aa', I'm going to - Dim aa - it's just a variable as a new instance of Mark. Ok, now what I just told this thing was that - I want you to use the Mark class and create a new object off of it and call that object aa. Now when I type aa and period - aa. - you'll notice my object as methods, the sub procedures of this class. And you'll notice here, do something and say something, now get type is inherited, we'll talk about that later. But do something and say something and so here say something and do something. Now notice you cannot see this, it does not show up in this list because it's private. And this is part of that encapsulation thing we talked about earlier. I've encapsulated this method away from this, so you'll also notice that my variables are here. X and Y, they show up as properties here. Now if I call 'say something' - and let me make it happen this way so you can tell what I'm doing - if I can double click say something, notice I'm executing aa.SaySomething. Ok and so I'm going to build this project, then I'm going to go out to the command line and run class test. And you'll notice "I did something" appears. Why? Because we asked this thing to run SaySomething, and SaySomething writes to the line to the console 'I did something' and that's exactly what happened. Now the private one here, I want to show you encapsulation while we are here. How can I use this? Well when I call public SaySomething right here, I can also call YouCannotSeeThis, and when I do it will run this and cause this to print out. So I can't call it from the outside but I can call from inside my class. So I'm going to build my project again, and then I'm going to go run from the command line. When I run classtest, you'll notice "I did something" and "you couldn't see this"; "you couldn't see this" comes because SaySomething ran and then it called YouCannotSeeThis, which jumped down and ran our private sub. We've encapsulated this away from our users, and it will only run when we say it runs inside the class. Now notice something else I can do, I can also - Dim bb As New Mark () - and with bb, I can call DoSomething. And DoSomething down here, will put some code in there to say this was called by bb. So then if I save that and build it, I will run this - Call classtest - and notice - this was called by bb - shows up. Now understand something, this are two totally separate objects here aa and bb. They have a common blueprint, but these are two separate objects now and they were both created from here. So that's how we instantiate a class, we Dim a variable and we create this variable as a new instance of whatever class. Now we are unlimited as to how many classes we want to create from this. And if you will notice, we can continue on using this particular class. So that's the way we use classes. That's the way we Dim objects and create objects and use the objects and in .NET, we don't have to worry about cleaning these objects up. As soon as we stop using them and stop running the program, the garbage collector will take care of them for us.
| Course: | Microsoft Visual Basic .NET |
| Author: | Mark Long |
| SKU: | 33433 |
| ISBN: | 1932072349 |
| Release Date: | 2003-05-27 |
| Duration: | 6 hrs / 87 lessons |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |