Data Types: CASTRO, Emmanuel G. (COE 221L 2:35-4 PM MWF) September 26, 2011
Data Types: CASTRO, Emmanuel G. (COE 221L 2:35-4 PM MWF) September 26, 2011
Data Types
Visual Basic is capable of storing and working with many different data types. Table 5.1 lists each of the data types supported by Visual Basic.
Data Type
Table 5.1: Visual Basic Supported Data Types Storage Value Range Requirements (in Bytes) True or False 0 to 255 0 to 65535 January 1,0001 to December 31, 9999 0 to +/- 79,228,162,514,264,337,593,543,950,335 -1.79769313486231570E+308 to - 4.94065645841246544E-324 for negative number and 4.94065645841246544E-324 to 1.79769313486231570E+308 for positive numbers -2,147,483,648 to 2,147,483,647 -2,147,483,648 to 2,147,483,647 Any type of variable -128 to 127 -32,768 to 32,767 -3.402823E+38 to -1.401298E-45 for negative numbers and 1.401298E-45 and 3.4028235E+E38 for positive numbers Up to two billion characters 0 to 4,294,967,295 0 to 18,446,744,073,709,551,615 0 to 65,535 1 2 8 8
Decimal 16
4 8 4 1 2 4 Varies 8 2
Ulnteger 4
As Table 5.1 shows, Visual Basic supports a large collection of data types. Each data type, except the object data type, is capable of storing a specific type of data. As Table 5.1 also shows, the amount of memory required to store data varies based on its data type. Visual Basic is very flexible. If you don't tell Visual Basic what the data type is for a particular piece of data, it assigns the data a default data type of Object .
Trap Although convenient , using the Object data type is not the most efficient option and will cause your application toconsume additional memory. Although a variable with a data type of Object can store any type of value, it cannot do so as efficiently as a variable that has been assigned the correct data type. Therefore, I strongly recommend that you always specify the data type for your variables. Just make sure when you do so that you specify a data type that accurately matches the type of data to be stored and that is capable of handling the size of the data to be stored. Trick When you specify the correct data types, you set up your Visual Basic programs to run faster by reducing the amount of memory used by the application and by eliminating the need to later convert data from one data type to another. However, I wouldn't invest too much time in analyzing the optimum data type for every variable that you ever need to create. In most cases, you can strike a good balance between program efficiency and memory usage versus your development time by using String, Integer, Double, Boolean , and Date .
By specifying a data type, you tell Visual Basic what range of values are allowable for a variable as well as what actions can be performed on the variable. For example, by specifying one of the numeric data types, you tell Visual Basic that it can perform mathematic calculations using the variable.
FUNCTIONS
Visual Basic 2005 is the name used to refer to the Visual Basic .NET, Microsoft having decided to drop the .NET portion of the title. For this release, Microsoft added many features, including:
Edit and Continue Design-time expression evaluation. The My pseudo-namespace (overview, details), which provides:
easy access to certain areas of the .NET Framework that otherwise require significant code to access dynamically-generated classes (notably My.Forms)
Improvements to the VB-to-VB.NET converter[2] The Using keyword, simplifying the use of objects that require the Dispose pattern to free resources
Just My Code, which when debugging hides (steps over) boilerplate code written by the Visual Studio .NET IDE and system library code Data Source binding, easing database client/server development
The above functions (particularly My) are intended to reinforce Visual Basic .NET's focus as a rapid application development platform and further differentiate it from C#. Visual Basic 2005 introduced features meant to fill in the gaps between itself and other "more powerful" .NET languages, adding:
generics[3] Partial classes, a method of defining some parts of a class in one file and then adding more definitions later; particularly useful for integrating user code with auto-generated code
Nullable Types[4]
Support for unsigned integer data types commonly used in other languages
a fully object-oriented language backed by the .NET Framework, which consists of a combination of the Common Language Runtime (a virtual machine using generational garbage collection and a just-in-time compilationengine) and a far larger class library. The increased breadth of the latter is also a problem that VB developers have to deal with when coming to the language, although this is somewhat addressed by the My feature in Visual Studio 2005. The changes have altered many underlying assumptions about the "right" thing to do with respect to performance and maintainability. Some functions and libraries no longer exist; others are available, but not as efficient as the "native" .NET alternatives. Even if they compile, most converted VB6 applications will require some level of refactoring to take full advantage of the new language. Documentation is available to cover changes in the syntax, debugging applications, deployment and terminology.
A true conditional operator, "If(condition as boolean, truepart, falsepart)", to replace the "IIf" function. Anonymous types Support for LINQ Lambda expressions XML Literals Type Inference Extension methods