VB.Net Data Types and Variable Declaration with DIM
VB.Net Data Types refers to a type of data that any variable can store in vb.net. This variable belongs to different data types and determines how much space it occupies in storage memory allocated. VB.Net Data Types includes include the following.
What are Data Types in VB.Net?
VB.Net Data Types
- Boolean
The storage allocation depends on the implementing platform. The default values for VB.Net Data Type Boolean is TRUE or FALSE.
- Byte
Values range from 0 to 255 (unsigned).
- Char
Values range from 0 to 65535 (unsigned).
- Date
The storage space is 8 bytes. Values range from 0:00:00 (midnight) on January 1, 0001 through 11:59:59 PM on December 31, 9999.
- Decimal
The storage space is 16 byte. From 0 through +/-79,228,162,514,264,337,593,543,950,335 (+/-7.9…E+28) with no decimal point; 0 through +/-7.9228162514264337593543950335 with 28 places to the right of the decimal
- Double
-1.79769313486231570E+308 through -4.94065645841246544E-324, for negative values
4.94065645841246544E-324 through 1.79769313486231570E+308, for positive values - Integer
has a storage space of 4 bytes. Values range between -2,147,483,648 to 2,147,483,647 (signed).
- Long
It has a storage space of 8 bytes. From -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807(signed)
- Short
It has a storage space of 2 bytes. -32,768 through 32,767 (signed)
- Single
It has a storage space of 4 bytes. -3.4028235E+38 through -1.401298E-45 for negative values;
1.401298E-45 through 3.4028235E+38 for positive values - String
The storage allocation depends on the implementing platform. Values from 0 to approximately 2 billion Unicode characters.
VB.NET Variables
What is a Variable? Variable is the most important in computer programming. All programming languages used variables to store and hold temporary data until it is released.
You will not appreciate the importance of variableS at this moment. But as you continue in programming you will realize what I’m talking about.
In declaring variables, the first thing that you have to do is to type the “Dim“.
See the Example below:
Dim name As String name = "Janry"
Here’s the example to display the value stored in a variable.
Dim name As String name = "Janry" MsgBox(name)
VB.Net Data Types and Variable Declaration with Dim in Actual Program.
In this section, we will now perform some of the most commonly used in the vb.net data type together with the use of vb.net variables using DIM for the declaration of VB.Net Variables.
Steps to Perform the VB.Net Data Types and variables
Step 1. Open Visual Studio and Create a new Project.
Step 2. Create a Windows Form Application. Follow the steps in the image below.
Step 3. Add a Button to Windows Form.
Step 4. Change the Text property of the button to “Test Variables”. Then Double click the Button and the Following Code.
Dim bool As Boolean
Dim bday As Date
Dim age As Integer
Dim money As Decimal
Dim str As String
The code above is only a variable declaration with Dim. Dim means Dimension. If you are going to read the declaration, you say “The Dimension of variable name as Data Type”.
Step 5. Assign a value to a VB.Net variable. Add the following code.
bool = True
bday = Today
money = 9.5
age = 25
str = "Still I am Happy!"
Step 6. Display the result of using Messagebox. Add the following code.
MsgBox("The Boolean Value is set to :" & bool)
MsgBox("Today " & bday & "is my birthday!")
MsgBox("And I am now " & age & " Years old!")
MsgBox("And I only have " & money & " dollar in my pocket")
MsgBox(str)
Step 7. Press “F5” to run the Project.
When you run the project and click the “Text Variable” button. you will see the following message box below.
Sample output of VB.NET using boolean
Sample output of VB.NET using Date
Sample output of VB.NET using Integer
Sample output of VB.NET using Decimal
Sample output of VB.NET using String
Summary
In summary, we have tackled VB.Net Data type and learn what would be the possible value of different data types when assigning to a specific vb.net variable.
For more examples, you may visit it guru99.com.
Inquiries
If you have any questions or suggestions about this tutorial, please feel free to leave a comment below.
This tutorial is the continuation of our previous tutorial entitled VB.NET Tutorials for Beginners with Examples.