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).
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:
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 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 :
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.
The answers with this data type have 16 places of accuracy. This data type allows you more than 300 digits.
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 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 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.
Use boolean data type when you need data to be either true or false.
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.