An Introduction to Object Oriented Database Development with VB.NET 2005 - Explanation continued
(Page 3 of 5 )
The first and most important issue to remember is that a class is simply a template/definition. A class is very much like a user-defined data type. A data type cannot hold data by itself. A variable (which allocates some memory) must have a definition based on a data type to hold some value. The value is stored in the memory allocated by the variable.
In very much the same way, a class doesn’t contain any data on its own. We need to create something like a variable to work with a class, or to access class members. Any variable which is created on the basis of the class is termed an “object” (or “instance”). Every “object” you create based on a class must be instantiated (or allocated with memory) with the operator “new.” The process of instantiation is simply the calculation of memory to be occupied by “class members” and the allocation of the same.
Let us consider the first statement in “btnSearch_click:”
Dim ep As New Emp
The above statement creates and instantiates an “object” (or “instance”) named “ep” based on the class “Emp.” Once the object is created/instantiated, we can access all of its members programmatically. Proceeding further, we have the following:
ep.load(Me.txtEmpno.Text)
The above statement executes the method “load” available in the object “ep.” The method “load” accepts a parameter (therefore called a “method with parameters”) to retrieve the information of the “empno” sent to it. Once the method is executed successfully, all the information of that “empno” is assigned to the “fields” of the class. We access the fields of object “ep” using the following statements:
Me.txtDeptno.Text = ep.m_deptno
Me.txtEname.Text = ep.m_ename
Me.txtSal.Text = ep.m_sal
Next: Expanding the class to handle errors >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee