Variables in VB.NET

How to declare variables in VB.NET?


Visual 2008 Variables

Variables in 2008 are used to store values and also they have a datatype and a unique name.
Naming Convention:

Variables in Visual Basic should start with an alphabet or a letter and should not contain any special characters like %,&,!,#,@ or $. The variable should not exceed 255 characters.
Scope of Variables:

A variable declared in the general declaration of a form can be used in all the procedures. Variables declared inside a procedure will have a scope only inside the procedure, so they are declared using the Dim keyword.

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim c As Integer
c = Val(TextBox1.Text) + Val(TextBox2.Text)
TextBox3.Text = c
End Sub
End Class

In the above example, Dim statement is used to declare variables, c that can be used within the sub procedure.

Visual Basic Tutorial

Ask Questions

Ask Question