In Visual Basic, Variables will represent storage locations, and each variable will have a particular data type to determine the type of values the variable can hold.
Visual Basic is a Strongly Typed programming language. Before we perform any operation on variables, it’s mandatory to define the variable with a required data type to indicate the type of data the variable can hold in our application.
Following is the syntax of declaring and initializing variables in visual basic.
If you observe the above variable declarations, we added a required data type after the variable name to tell the compiler about the type of data the variable can hold.
|Dim||It is useful to declare and allocate the storage space for one or more variables.|
|[Variable Name]||It’s the variable's name to hold the values in our application.|
|As||The As clause in the declaration statement allows you to define the data type.|
|[Data Type]||t’s a type of data the variable can hold, such as integer, string, decimal, etc.|
|[Value]||Assigning a required value to the variable.|
Now, we will see how to declare and initialize the values to the variables in visual basic applications with examples.
Following is the example of using the variables in visual basic.
The above example shows that we defined multiple variables with different data types and assigned the values based on our requirements.
When we execute the above example, we will get the result as shown below.
This is how we can declare and initialize the variables in Visual Basic applications based on our requirements.