Your current position:
Home 
  Visual Basic
    Programming with objects
      Creating your data-types

Creating Your Own Data Types

In Visual Basic you can also create your own types of data by combining the basic types of data. Situation: You are working on this program that needs to store students in a database. Each student must have a Name, Age, Class.

Problem: How will I can store this information in one single variable ?
Answer: it’s very simple create your own data type that will store all this information:
We will do this using the Type statement

 Type Students
    
Name As String
    
Age As Integer
     Grade As String
 End Type

You must declare it in the declaration section af a module, or form (if you are declaring it in a form you must specify the Private keyword before the Type keyword)

Declaring variables as your defined type.

Syntax:
Dim [variable name] As Student

Example:
Dim Student As Students

Accesing it’s members. After the variable is declared you can tread it as an object:

 Student.Age = 19

 Student.Name = “Smith”

 Student.Grade = “2nd”