Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/myscript/public_html/classes/classdb.php on line 42
User Defined Data Types in VB.NET

User Defined Data Types in VB.NET

How to know about the User Defined Data Types in VB.NET?

Explanation

User Defined Data Types

User defined data type in VB.net 2008 is a collection of variables of different primitive datatypes available in Visual Basic.net 2008 combined under a single user defined data type. This gives the flexibility to inlcude real time objects into an application.
User defined data types are defined using a Structure Statement and are declared using the Dim Statement.
Structure Statement:

The Structure statement is declared in the general declaration part of form or a Module.
Syntax:

[ Public | Protected | Friend | Protected Friend | Private]
Structure varname elementname [([subscripts])] As type
[elementname [([subscripts])] As type]
. . .
End Structure

In the above syntax varname is the name of the user defined datatype, that follows the naming convention of a variable. Public option makes these datatypes available in all projects, modules, classes. If declared Private the user defined datatypes can be used where it is declared, same applies to Friend and Protected Friend. elementname is the name of the element of an user defined datatype. type is the primitive datatype available in visual basic.
Dim Statement:

This is used to declare and allocate a storage space for an variable or an user defined variable.
Syntax:

Dim variable [As Type]
Example:

Structure EmpDetails
Dim EmpNo As Integer
Dim EmpName As String
Dim EmpSalary As Integer
Dim EmpExp As Integer
End Structure
Public Class Form1
Private Sub Button1_Click
(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles Button1.Click
Dim TotalSal As New EmpDetails()
TotalSal.EmpNo = TextBox1.Text
TotalSal.EmpName = TextBox2.Text
TotalSal.EmpSalary = TextBox3.Text
TotalSal.EmpExp = TextBox4.Text
TextBox5.Text = Val(TotalSal.EmpSalary) *
Val(TotalSal.EmpExp)
End Sub End Class
Description:

In the above example, Structure statement is used to define user defined datatypes, EmpDetails which is assigned to TotalSal.

Visual Basic Tutorial


Ask Questions

Ask Question