In Lesson 4 of our VB2010 tutorial, we have explained the concepts of Object Oriented Programming. Now, let us show you how to create a class object that can calculate your BMI (Body Mass Index).
To create a class, start VB2010 as usual and choose Windows Applications. In the VB2010 IDE, click on Project on the menu bar and select Add Class, the Add New Item dialog will appear.
Select Add Class and the default class Class1.vb will appear as a new tab with a code window. Rename the class as MyClass.vb. Rename the form as MyFirstClass.vb.
In the MyClass.vb window, enter the follow code
Public Function BMI(ByVal height As Single, ByVal weight As Single)
BMI = Format((weight) / (height ^ 2), “0.00″)
End Function
Now you have created a class (an object) called MyClass with a method known as BMI.
Read on by click on the following link: