VISUAL BASIC
LANGUAGE
Data Types
Converting between data types
List of conversion functions
Example
VB Data conversion functions
VB supports a number of ways of converting
from one type of variable to another.
Checking Data types
• VB has a number of data verification functions.
Declaring Arrays
• Arrays are stored a fixed-size sequential collection of elements of
the same data type.
• To dimension arrays, we can use Dim(standard arrays),
Redim(dynamic arrays), Static(arrays don’t change), Private(Arrays
private to the form or module), Protected(arrays restricted to a
class or classes derived from that class), Public(arrays global to
whole program).
Standard Array
• Dim statement to declare a standard array.
Example
Dim Data(30)
Dim String(10)As String
Dim TwoArray(20,40)As Integer
Dim Bounds(10,100)
• Here, Data array has 30 elements.
• 0 is the lower bound of this array and 29 is the upper bound of this
array.
• Here, Bound array has two indices, one stores 0 to 9, other stores
0 to 99.
Example
We can also initialize the array with the values 10,3,2.
Dim Data() = {10,2,3}
Dynamic Arrays
• We can use Dim statement to declare an array with empty
parentheses to declare a dynamic array.
• It can be dimensioned or redimensioned with ReDim statement.
• We can use the Preserve keyword to preserve the data in an
existing array when we change the size of the last dimension.
• Example:-
Example:-
Handling Strings
• Declaring a string,
Dim str As String
• Also initializing a string,
Dim str As String = “Welcome”
Output:-
• ([Link])UCase function to convert strings to uppercase.
• ToUpper function to convert strings to uppercase.(String Class)
• Substring method to extracting the word from the starting value
and length of the substring.
• Mid method to get the substring from the middle of another string.
String Handling Functions
Fixed-Length Strings
• In VB6, we specify a non-changing length for a string.
• In [Link], VBFixedStringAttribute to declare fixed-length strings.
• Example:-
• In VB6, declares a string of 1000 characters.
Dim str As String * 1000
• In [Link],
<VBFixedString(1000)> Public Str As String
Converting Strings to Numbers
• Using Str to return a string representation of a number.
• Using Val to convert a string to a number.
• Example:-
Converting between character and character
codes
• Asc – Takes a character and returns its character code.
Example:- Asc(“A”) returns 65.
• Chr – Takes a character code and returns the corresponding
character.
Example:- Char(65) returns A.
Vb Operators
• There are various types of operators in Visual Basic.
• Arithmetic operators
• Assignment operators
• Comparison operators
• String Concatenation operators
• Logical/Bitwise operators
Example
Commenting the code
• In Visual Basic, add comments to the code using (‘) apostrophe.
Example:-