From the course: Visual Basic Essential Training

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Add procedures to a class

Add procedures to a class

- [Instructor] To add a class to my project, I can right click on the project and choose add class, and then give my class a name. What I'll do in this example is just change my module to a class, that's real simple to do. I'll just go to number generator and then now where it says module, I'll change that to class. And you'll see the Visual Studio changes the end class to match. Now, when you have a class, you need to instantiate the class in order to use it. So if I go over here to this code, you'll see that I'm getting an error now because I'm not using an instance of the class. So what I'll do here is say dim gen as new, and then I want a number generator. That gives me this variable that references an instance of this new class, what we call an object. Then I can go here and say gen. Now it's valid. So let's go through the same thing in this even handler. We'll go down here and we'll copy this code, place it down here, and then this is supposed to be the even button. So this is…

Contents