Visual Basic .NET/Variables

Variables
In programming a variable is simply a place to store data. A variable has a name and a data type. In Visual Basic .NET, a variable is declared using the Dim (short for Dimension) statement. Here is the syntax:

varName is the name of your variable.

varType is the data type of the variable. Types include string, integer, double, boolean, etc.

For example, to declare an integer named MyInt use:

By default, the variables case doesn't allow to distinguish them, so myint will automatically be converted in MyInt by the IDE if it's declared like that.

On the other hand, to make a program ignore the case in the string values,  should be added.

Data Types
Data Types define the type of data that a variable can store. Some variables store numbers, others store names. The built-in VB.NET type aliases and their equivalent .NET Framework types follow:

Assigning Values
A value is the data contained in a variable. To assign a value to a variable that is already declared, use an equal sign.

Suffix for Literals
Integral literals, such as 42 and 1000, are of type Integer by default. String and character literals, such as "Hello World" and "À", are of type String by default. To specify the type for a literal, suffixes are used. The suffixes are appended immediately after the literals, in the manner &lt;literal&gt;&lt;suffix&gt;, without any whitespace between.

Examples
For string and char variables, use double quotes around value: For date variables, use hashes/pounds around the value, in the format #&lt;month&gt;/&lt;day&gt;/&lt;year&gt; &lt;hour&gt;:&lt;minute&gt;:&lt;second&gt; &lt;AM|PM&gt;#:

For all others, remove the quotes and hashes/pounds:

Initial Value
To assign a variable the value of another variable, simply replace the value on the right side of the equal sign with the name of the variable that holds the desired data.

You can also assign a value to a variable in the declaration itself.

Important: Visual Basic always assigns the value of the right variable to the left variable. The variable on the left takes the value of the right variable. The variable on the right does not change.

Constants
Constants are like variables that don't change. They take the place of values that you would not like to type over and over. Constants are declared using the keyword "Const". Their values are defined in their declaration - they also use data types. Here is the syntax: Here is an example: Constants are very useful when you need to type the same numbers/strings/etc many times. For example, to convert from radians to degrees you can type 180/Pi constant: And use it like this: This constant is useful in functions like Sin, Cos, Tan, Arctan, etc.

de:Visual Basic .NET: Variablen Visual Basic .NET/Variables