3 Declare Variable in VB.NET

To Declare Variable in VB.NET  :  We require a keyword called as "Dim".

Dim: It declare and allocates storage space for one or more variables.

Syntax :  Dim{ <var> [As [New] dataType [(boundList)] ] [=initializer] }
     
eg:   Dim Message As String = "Coding Atharva"



Code: 

Public Class Form1

    Dim Message As String = "This is a message string"
    Dim intvar As Integer = 25


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MessageBox.Show(Message)
        MessageBox.Show(intvar)


    End Sub
End Class



Note: Do not give semicolon at the end.




Before Click: 



After First Click:



After Second Click:



Previous
Next Post »