Home
Username:
Password:
Microsoft Visual Basic .NET Tutorials

Modules / Creating a Module




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.


Learn More

Subtitles of the Movie

Ok now that we've talked about modules and how they fit together, let's go into visual studio and actually build some of these things and play with them and I'll step through this slowly. And again you are going to have to endure my typing. So we are going to go back to a console application again. So that I can show you how this code works in a very simple way. Notice when I open a console application, I automatically have a module1 here. And now this module is simply going to contain all the code I write. Notice that I can put - Public Sub Mark() - then I can put code in there and I can put Public Sub Test() in here. And I would put code there. Then I can create a Class here Public Class, call it ClassTest and inside there I can put a Sub, Public Sub DoSomething(). Then I would put code there. Now notice what's happened in my module. I have some Subs, then I have a Class. Now within the Sub Main area notice I can just call Mark right here. Ok just by typing Mark and you'll know that it recognizes Mark, and this is making a call to the Sub procedure. Ok, ClassTest to get to Sub DoSomething I will have to first instantiate an object of ClassTest. Ok, so if I - Dim a as New ClassTest() - now A exposes DoSomething to me, so that's nothing radically different than what we've been doing all along. So let's take this off and let's do something a little bit more interesting now. Let's go create a Module2. So notice the syntax on this, we just say module and the name, so I will say - Module Module2 - and notice when I hit enter an - End Module - appears. And now I'm going to say - Public Sub PrintThis() - and code would go here, then we will say - Public Sub FileThis() - and code will go here. Now notice in this module, in module2, I only have two Subs. And so I will come up here to my Sub Main and if I type PrintThis, notice it will make a call to PrintThis. Now why because this is all within the same assembly and it can see this module, this is shared. OK I don't have to instantiate an object. Now let's do something kind of interesting. Notice I've got a Public Sub Mark in Module1, let me go down here and do Public Sub Mark in Module2. Now if I call Mark here it's not going to have any problems, but trust me it's going to run the Mark that's in the same module here. Ok, so what I need to do is tell it to run the Module2 Mark. So what I can do is differentiate and type module2, and notice when I typed module2 it exposes PrintThis and FileThis and Mark, and I can just call Mark. But notice these modules have totally separated how my Classes are hailed. Now let me put another Class in here and notice I have a Class up here called ClassTest. Ok I'm going to create a Class Test down here in module-2 and then I'll put a Public Sub in here, called DoSomethingElse() and then code of course will go here. Now notice we've got two Class Tests, I've got a Public Class Test in module2, a Public Class, ClassTest, let me make that ClassTest. So now I've got a ClassTest Class in both module2 and module1. So now if I Dim A as a new ClassTest which one is it getting? Well, you'll notice it is getting this one that has DoSomething. Well if you remember this Class Test down here says DoSomethingElse in module2. So how do I get to it? What I would do is when I create it I will call it module2 and notice now I can bring ClassTest, and now when I use A notice I'm getting DoSomethingElse which is the method inside this Class here, ClassTest. So you see again modules help us separate our code, separate our Classes and maintain an efficient manner of getting to all the code that we need in here. So I hope that makes sense, that's some information on modules You'll see modules used from time to time, and of course we can use namespaces and so forth in here. So do understand, you don't have to instantiate modules, you don't necessarily have to call them by name, unless in this instance we trying to differentiate between similar Classes in different modules. And so that's a, that's a good representation of a module, very simple example, taken from there and built on it and use it as you need to, to make your programs efficient. And with that we'll now move to structures. And in the next video we'll talk about structures, these are strange animals; they're new to VB .NET. And with structures we will finish out the code portion of this and then move into garbage collection from there.

Tutorial Information

Course: Microsoft Visual Basic .NET
Author: Mark Long
SKU: 33433
ISBN: 1932072349
Release Date: 2003-05-27
Duration: 6 hrs / 87 lessons
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available