From the course: Visual Basic Essential Training

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Add procedures to class

Add procedures to class - Visual Basic Tutorial

From the course: Visual Basic Essential Training

Start my 1-month free trial

Add procedures to class

- [Instructor] Procedures can be defined in classes too. To add a class to your project, right click and choose Add, Class. In this dialog, give your class a useful name and then click on Add. For this demonstration, rather than adding a new class, I'll just convert the code I already have in my module to a class. So, I'll cancel out of this dialog, and then open up NumberGenerator. It's a simple fix. Go up to the top line and where it says Module, change the word to Class. Visual Basic's editor fixes it on line one and on line 11. Now, I'll switch over to where I'm calling that code, and I can see that I have some issues. So, I'll hover over one of these to find out what the problem is. GetRandomEvenNumber is not declared. The reason this is happening is because there's been a change in scope. When I have code in a module, and it's public, it's visible throughout the entire project. This is still true, but now…

Contents