Unit 3 (A)
Unit 3 (A)
⦁ Types of Token
a. Keywords
b. Identifier
c. Literal
d. Operator
⦁ Keyword are the predefined words that convey a special meaning for
the language compiler. These are known as reserved words
because it convey special meaning.
Eg: DIM, Byte, For, While, class, module, as,etc.,
⦁ Identifiers are the names given to function variable, class, array,
function etc.,
⦁ Rules of Identifier
AND The Binary AND Operator are used to copy the common binary bit in the
result if the bit exists in both operands.
OR The Binary OR Operator is used to copy a common binary bit in the result if
the bit found in either operand.
XOR The Binary XOR Operator in VB.NET, used to determine whether a bit is
available to copy in one operand instead of both.
NOT The binary NOT Operator is also known as the binary Ones' Compliment
Operator, which is used to flip binary bits. This means it converts the bits
from 0 to 1 or 1 to 0 binary bits.
<< The Binary Left Shift Operator is used to shift the bit to the left side.
>> The Binary Right Shift Operator is used to shift the bit to the right side.
⦁ The Assignment Operators are used to assign the value to variables
in VB.NET.
Operator Description Example
& It is an ampersand symbol that is used to bind two or more Result = Wel &
operand together. Furthermore, a nonstring operand can come,
also be concatenated with a string variable ( but in that Result = Welcome
case, Option Strict is on).
+ It is also used to add or concatenate two number or string. Result = Wel +
come,
Result = Welcome
Operator Description Example
Named
User assigned name, data type and value
Use CONST keyword to declare
Const COMPANY_ADDRESS_String As String = "101 S. Main Street"
Const SALES_TAX_RATE_Decimal As Decimal = .08D
Intrinsic
System defined within Visual Studio
Assigning Values to Constants
Declare the data type of numeric constants by appending a type-declaration
character
• Decimal - D • Long - L
• Double - R • Short - S
• Integer - I • Single - F
Method Convert To
Integer.Parse Integer
Decimal.Parse Decimal
.ToString String
Conversion Examples
quantityInteger = Integer.Parse(quantityTextBox.Text)
priceDecimal = Decimal.Parse(priceTextBox.Text)
wholeNumberInteger = Integer.Parse(digitString)
resultLabel.Text = resultDecimal.ToString( )
countTextBox.Text = countInteger.ToString( )
idString = idInteger.ToString( )
⦁ Tells how much storage/memory to be allocated to a variable
⦁ Types of Data type
a. Boolean values
b. Integers
e. Date
⦁Boolean datatype can hold only two values one is TRUE and other is
FALSE.
Eg: Dim value As Boolean //variable declaration
value=True
or
value=False
⦁ Integer datatype allows a variable to store whole numbers
Do
[ statements ]
Loop [{ While | Until } condition ]
⦁ Eg: Dim x As Byte=1
Do
Console.WriteLine(“The value of the variable is {0}”,x)
x=x+1
Loop While x<=10
⦁ The only difference between do while and do until is that the first one
loops is execute as long as the condition is true, while the second
one loops execute as long as the condition is false.
⦁ Repeats a group of statements a specified number of times.
Next
⦁ It repeats a group of statements for each element in a array or
collection. This loop is used for accessing and manipulating all
elements in an array or a VB.Net collection.
Statements
End While
Example: Dim a As Integer = 10
While a < 20
Console.WriteLine("value of a: {0}", a)
a=a+1
End While
⦁ Exit statement is used to terminate the procedure (for, while, do,
select case, function etc.) or exit the procedure and pass control
immediately to the next statement of the termination procedure
⦁ Syntax:
Exit { Do | For | Function | Property | Select | Sub | Try | While }
⦁ Eg:
Dim index As Integer = 0
For index =0 to 10
Console.Writeline(“index value is {0}”,index)
Exit For
End for
⦁ Continue statement is used to skip the particular iteration of the
loop and continue with the next iteration. Generally,
the continue Statement is written inside the body of the For, While
and Do While loop with a condition.
⦁ Syntax:
Continue { Do | For | While }
⦁ Eg: Dim i As Integer = 10
While i < 20
If i = 14 Then
Console.WriteLine(" Skipped number is {0}", i)
i += 1
Continue While
End if
Console.WriteLine(" Value of i is {0}", i)
i += 1
End While
⦁ GoTo statement is known as a jump statement. It is a control
statement that transfers the flow of control to the specified label
within the procedure.
⦁ Syntax:
GoTo label1
For i As Integer = 0 To 5
Console.WriteLine(" Enter the value for arr[{0}] : ", i)
arr(i) = Console.ReadLine()
Next
Console.WriteLine(" The array elements are : ")
For j As Integer = 0 To 5
Console.WriteLine("{0}", arr(j))
Next
⦁ In VB.NET, a multidimensional array is useful for storing more than
one dimension in a tabular form, such as rows and columns.
⦁ Declaration
For i As Integer = 0 To 1
For j As Integer = 0 To 3
Console.WriteLine("Enter the value for array[{0}][{1}]", i, j)
arr(i, j) = Console.ReadLine()
Next
Next
For i As Integer = 0 To 1
For j As Integer = 0 To 3
Console.WriteLine("The value of the array is {0}", arr(i, j))
Next
Next
⦁ Dynamic Arrays can resize the capability of the Array at runtime.
when you are in a situation that you do not know exactly the number
of elements to store in array while you making the program.
⦁ It allows us to insert or store the number of elements at runtime in
sequentially manner.
⦁ “ReDim” is the keyword used for resizing
⦁ Initial declaration
Eg: Dim scores() As Integer
⦁ Resizing
Eg: ReDim scores(1)
⦁ If you want to keep the existing items in the Array , you can use the
keyword Preserve .
Eg: ReDim Preserve scores(2)
Eg: Dim marks() As Integer
ReDim marks(2)
marks(0) = 85
marks(1) = 75
marks(2) = 90
ReDim Preserve marks(10)
marks(3) = 80
marks(4) = 76
marks(5) = 92
marks(6) = 99
marks(7) = 79
marks(8) = 75
For i = 0 To 10
Console.WriteLine(i & vbTab & marks(i))
Next