article

Data types in Visual Basic

Email
Submitted on: 1/29/2015 11:54:00 AM
By: Deepanjan Datta (from psc cd)  
Level: Intermediate
User Rating: By 8 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 993
 
     Learn everything about data types supported by Visual Basic!!!(Don't look at the ratings because this article has been updated to make it as complete as possible!!!)

 
				

Data types in Visual Basic


Just as ice-creams come in different flavors,
data comes in diffrent types.

Visual Basic handles 14 standard data types(it is also possible to define your data types).

String


The string data type holds characters. Avariable holding a string is called, naturally enough, a string variable.
Here is a declaration of string variable:
Dim strVariableName as String
String variables can theoritically hold about 2 billion characters. On a specific computer, though, the variable may hold less due to memory constraints, overhead requirements for Windows or the number of strings used in the form.
 One of the commonest uses of string variables is to pick up information contained in a text box.
Here is how:
strVariableName=Text1.Text

Integer


Integer variables hold relatively small integer values (between -32,768 to +32,767). Integer arithmetic is very fast but is restricted to these ranges or you will get an error message.
Here is a declaration :
Dim intVariableName as Integer

Long integer


Long integer variables hold integers between -2,147,483,648 and +2,147,483,647. Long integer arithmetic is also fast and there is very little (if any) performance penalty on modern machines.
Here is a declaration :
Dim intALongInteger=123456789

Single precision


Single precision variables have a decimal point but one can be sure of accuracy of seven digits. For example if an answer comes as 12,345,678.97 then the 8.97 may not be correct.
The range of these numbers is upto 38 digits. 
Calculations will always be approximate for these types of variables; exact answers are impossible to guarantee.

Double precision


The answers with this data type have 16 places of accuracy. This data type allows you more than 300 digits.

Currency


Variables of this data type are designed to avoid certain problems inherent in switching from binary fractions to decimal fractions.
 The currency type can have four digits to the right of the decimal place and upto fifteen digits to the left of the decimal point.
Arithmetic will be exact within this range.

Date


Date data type gives you convenient way to store both date and time information for any time between midnight on January 1, 100 to midnight on December 31, 9999.

Byte


Byte type was added to Visual Basic 5. It can hold integers between o and 255. This is a great convenience when you need to save space and it makes certain arrays much smaller than they would have been in earlier versions of Visual Basic.

Boolean


Use boolean data type when you need data to be either true or false.

Variant


The variant data type is designed to store all the different possible Visual Basic data received in one place. If Visual Basic is not told what data type a variable belongs to, Visual Basic puts the variable in this data type. Using variant type rather than using a specific type is slower because of the conversions needed. It takes up more memory.
Those are the data types supported by Visual Basic. Happy programming!!!


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.