What Are User-defined Types In VB And How They Are Implemented?

2

2 Answers

raaga Profile
raaga answered
The primitive data types (like integer, string, long etc.) can represent only a single or multiple variables of same data type, but sometimes we are needed to represent some real world objects (e.g. records) that is not possible by these simple data types.

Thus, like many other programming languages, in VB there is a flexibility to define user-defined data types. These user-defined types are derived types because these are collection of variables of different primitive types.These types are also sometimes referred to as aggregates under the one name. We can define the user-defined type as:

Private Type myRecord
Num as integer
Sum as long
Balance as currency
End Type

Where 'Type' is a keyword and 'myRecord' is name of this user-defined type.
Between the first statement and last statement of the above type definition, we can declare as many variables of any primitive type as we needed.
The myRecord is user-defined type that consists of three variables as shown above.
We can declare the variables of this type simply as:
Dim record1 as myRecord
where 'record1' is a variable of the type 'myRecord' and it consists of all the variables defined in myRecord definition.
We can access and manipulate all the primitive type variables that are now a part of 'record1' by the following syntax:
record1.Num=0
record1.Sum=0
record1.Balance=0$
raaga Profile
raaga answered
The primitive data types (like integer, string, long etc.)Can represent only a single or multiple variables of same data type, but sometimes we are needed to represent some real world objects (e.g. records) that is not possible by these simple data types. Thus, like many other programming languages, in VB there is a flexibility to define user-defined data types. These user-defined types are derived types because these are collection of variables of different primitive types.

These types are also sometimes referred to as aggregates under the one name. We can define the user-defined type as:

Private Type myRecord
Num as integer
Sum as long
Balance as currency
End Type

where 'Type' is a keyword and 'myRecord' is name of this user-defined type.
Between the first statement and last statement of the above type definition, we can declare as many variables of any primitive type as we needed.
The myRecord is user-defined type that consists of three variables as shown above.
We can declare the variables of this type simply as:
Dim record1 as myRecord
where 'record1' is a variable of the type 'myRecord' and it consists of all the variables defined in myRecord definition.
We can access and manipulate all the primitive type variables that are now a part of 'record1' by the following syntax:
record1.Num=0
record1.Sum=0
record1.Balance=0

Answer Question

Anonymous