In Visual Basic, Data Types are useful to define a type of data the variable can hold, such as integer, float, string, etc., in our application.
Visual Basic is a Strongly Typed programming language. Before we perform any operation on a variable, it’s mandatory to define a variable with a required data type to indicate what type of data the variable can hold in our application.
Following is the syntax of defining data types in visual basic.
If you observe the above syntax, we added a required data type after the variable name to tell the compiler about the type of data the variable can hold.
|It is useful to declare and allocate the storage space for one or more variables.
|It’s the variable's name to hold the values in our application.
|The As clause in the declaration statement allows you to define the data type.
|t’s a type of data the variable can hold, such as integer, string, decimal, etc.
|Assigning a required value to the variable.
The following table shows the available data types in a visual basic programming language with memory size and range of values.
|It depends on the Platform.
|True or False
|0 to 255
|0 to 65535
|0:00:00am 1/1/01 to 11:59:59pm 12/31/9999
|(+ or -)1.0 x 10e-28 to 7.9 x 10e28
|-1.79769313486232e308 to 1.79769313486232e308
|-2,147,483,648 to 2,147,483,647
|-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
|4 bytes on a 32-bit platform, 8 bytes on a 64-bit platform
|Any type can be stored in a variable of type Object
|-128 to 127
|-32,768 to 32,767
|-3.4028235E+38 through -1.401298E-45 † for negative values; 1.401298E-45 through 3.4028235E+38 † for positive values
|Depends on Platform
|0 to approximately 2 billion Unicode characters
|0 to 4,294,967,295
|0 to 18,446,744,073,709,551,615 (1.8...E+19 †)
|0 to 65,535
|Depends on Platform
|Each member of the structure has a range determined by its data type and is independent of the ranges of the other members
Now, we will see how to use the Data Types in our visual basic applications with examples.
Following is the example of using the data types 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 use the data types in Visual Basic applications based on our requirements.