Blog
15+ BEST Windows Movie Maker Alternatives (Free/Paid)
Windows Movie Maker is a powerful and easy-to-use video editing application for Windows operating...
Data types determine the type of data that any variable can store. Variables belonging to different data types are allocated different amounts of space in the memory. There are various data types in VB.NET. They include:
In this tutorial, you will learn:
There are functions that we can use to convert from one data type to another. They include:
In VB.NET, the declaration of a variable involves giving the variable a name and defining the data type to which it belongs. We use the following syntax:
Dim Variable_Name as Data_Type
In the above syntax, Variable_Name is the variable name while Data_Type is the name to which the variable belongs.
Here is an example of a valid variable declaration in VB.NET:
Dim x As Integer
In the above example, 'x' is the variable name while Integer is the data type to which variable x belongs.
Initializing a variable means assigning a value to the variable. The following example demonstrates this:
Dim x As Integer x = 10
Above, we have declared an integer variable named 'x' and assigned it a value of 10. Here is another example:
Dim name As String name = "John"
Above, we have declared a string variable name and assigned it a value of John.
If you declare a Boolean variable, its value must be either True or false. For example:
Dim checker As Boolean checker = True
Above, we have defined a Boolean variable named checker and assigned it a value of True.
Let us demonstrate how to declare and initialize a variable using a code example:
Step 1) Create a New Project
Step 2) Create a Button
Step 3) Click the other tab located to the left of the design tab. You can also double click the button that you have added to the form.
Step 4) Add the following code to add text to the control:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim checker As Boolean
checker = True
MsgBox("The value of variable checker is : " & checker)
Dim x As Integer
x = 32
MsgBox("The value of variable x is : " & x)
Dim name As String
name = " gtupapers "
MsgBox("The value of variable name is : " & name)
End Sub
Step 5) You can now run the code by clicking the Start button located at the top bar:
Step 6) You should get the following form:
Step 7) Click Button 1. You should get the following dialog:
Click the OK button to move to the next dialog. It should be as follows:
Again, click the OK button to move to the next dialog. It should be as follows:
Here is a screenshot of the complete code for the above:
Explanation of code:
When creating an application, you may need a way of getting input from the user. This can be done using the ReadLine function of the Console class in System namespace. Once you have received the input from the user, you are required to assign it to a variable. For example:
Dim user_message As String user_message = Console.ReadLine
In the above example, we have defined a variable named user_message. The message read from the console has been assigned to that variable. Let us demonstrate this:
Step 1) Create a Console Application
Step 2) Add the following code to the workspace:
Module Module1
Sub Main()
Dim user_message As String
Console.Write("Enter your message: ")
user_message = Console.ReadLine
Console.WriteLine()
Console.WriteLine("You typed: {0}", user_message)
Console.ReadLine()
End Sub
End Module
Step 3) You can now run the code by clicking the Start button located at the top bar:
Step 4) Enter your Message
Here is the complete code for the example:
Explanation of Code:
VB.NET expressions are of two types:
Variables are lvalues, meaning that we can put them on the left side of the assignment operator. For example:
Dim x As Integer = 32
For numeric literals, they can neither be assigned nor can they appear on the left-hand side of the assignment operators since they are rvalues. For example:
32 = x
The above expression is wrong and will generate a compile-time error.
Windows Movie Maker is a powerful and easy-to-use video editing application for Windows operating...
What is Docker? Docker is a software development platform for virtualization with multiple...
Notepad++ is an open source code editor written in C++. It supports various programming languages...
What is Concurrency or Single Core? In Operating Systems, concurrency is defined as the ability of a...
What is CISC? CISC was developed to make compiler development easier and simpler. The full form of...
MAC includes a huge collection of the built-in app. However, there are many useful software that...