Hello, welcome to studentprojectguide.com . This is a simple program which will explain how to create variables in VB.NET. There are three main types of data types in VB.NET. The three main data types are Integer, Double and string. In VB.NET it works in just 3 steps. First is variable initialization, Second is Declaration, and third is execution.
In this program we created variables in global form. We created three types of different variables in this source code. After creating variables in the form load event values assigned to 3 variables. In the button click even message box which displays variable values in the popup.
Steps to create this program:
- First create variable – Start with dim (Dim is the statement to determine the variable type) .
- Dim VariableName as DataType (There are many datatypes in vb.net. But here we explained only three types of data types)
- Secondly initialize values to the variables. In the below program we initialized values in the form load event.
- Third step is execute and display values using messagebox. The messagebox funtion will display values in the alert box.
Here is the source code:
Public Class Form1 Dim num As Integer ' Integer variable without decimal points Dim amount As Double ' double with decimal points Dim custname As String ' string variable to put characters Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load num = 100 ' Assigning integer value amount = 200.53 ' Assigning value with decimal point custname = "Rajesh kumar" ' String variable records inside quote End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'This is to display results MessageBox.Show("num = " & num) MessageBox.Show("amount = " & amount) MessageBox.Show("custname = " & custname) End Sub End Class
Video tutorial: This video clearly explain how to create variables and how to display records in VB.NET.
Thanks for reading this article. If any doubts kindly post comments in the comment box.🔥13 Views