VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Data types in Visual Basic

by Deepanjan Datta (3 Submissions)
Category: Data Structures
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (8 Votes)

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!!!)

Rate Data types in Visual Basic

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!!!
 

Download this snippet    Add to My Saved Code

Data types in Visual Basic Comments

No comments have been posted about Data types in Visual Basic. Why not be the first to post a comment about Data types in Visual Basic.

Post your comment

Subject:
Message:
0/1000 characters