You are on page 1of 41

UNIT 2

Decision Control And Loop


Control
Data Types in VB.NET
Data types refer to an extensive system used for
declaring variables or functions of different
types.
Data Types
• Boolean
• Byte
• Char
• Date
• Decimal
• Double
• Integer
• Long
• Object
• Short
• String
Operators in VB.NET
• Arithmetic Operators :
Following table shows all arithmetic operators
supported by VB.Net.

Symbol Name
+ Addition
- Subtraction
/ Division
* Multiplication
% Modulo
\ Integer Division
^ Exponentiation
• Logical Operators :
Operator Description Example

And It is the logical as well as bitwise AND operator. (A And B)


is False.

Or If any of the two operands is true, then condition becomes true. (A Or B) is


True.

Not Use to reverses the logical state of its operand. Not(A


And B) is
True.

Xor It returns True if both expressions are True or both expressions A Xor B is
are False; otherwise it returns False. True.

IsFalse It determines whether an expression is False.

IsTrue It determines whether an expression is True.


• Bit Shift Operators :

Operator Description Example


And Bitwise AND Operator copies (A AND B) will give 12, which
a bit to the result if it exists in is 0000 1100
both operands.
Or Binary OR Operator copies a (A Or B) will give 61, which is
bit if it exists in either 0011 1101
operand.
Xor Binary XOR Operator copies (A Xor B) will give 49, which
the bit if it is set in one is 0011 0001
operand but not both.
Not Binary Ones Complement (Not A ) will give -61, which is
Operator is unary and has 1100 0011 in 2's complement
the effect of 'flipping' bits. form due to a signed binary
number.
• Bit Shift Operator

Operator Description Example


<< Binary Left Shift A << 2 will give 240,
Operator. The left which is 1111 0000
operand's value is moved
left by the number of bits
specified by the right
operand.
>> Binary Right Shift A >> 2 will give 15, which
Operator. The left is 0000 1111
operand's value is moved
right by the number of
bits specified by the right
operand.
• Relational Operators :

Operator Description Example


= Checks if the values of (A = B) is not true.
two operands are equal
or not; if yes, then
condition becomes
true.
<> Checks if the values of (A <> B) is true.
two operands are equal
or not; if values are not
equal, then condition
becomes true.
> Checks if the value of (A > B) is not true.
left operand is greater
than the value of right
operand; if yes, then
condition becomes
true.
• Relational Operators :
Operator Description Example
< Checks if the value of left (A < B) is true.
operand is less than the
value of right operand; if
yes, then condition
becomes true.
>= Checks if the value of left (A >= B) is not true.
operand is greater than
or equal to the value of
right operand; if yes,
then condition becomes
true.
<= Checks if the value of left (A <= B) is true.
operand is less than or
equal to the value of
right operand; if yes,
then condition becomes
true.
• Assignment Operators :

Operator Description Example


= Assigns values from right side C = A + B will assign value of
operands to left side operand A + B into C
+= Add AND assignment operator, It C += A is equivalent to C = C
adds right operand to the left +A
operand and assigns the result to
left operand
-= It subtracts right operand from the C -= A is equivalent to C = C
left operand and assigns the result -A
to left operand
*= It multiplies right operand with the C *= A is equivalent to C = C
left operand and assigns the result *A
to left operand
/= It divides left operand with the right C /= A is equivalent to C =
operand and assigns the result to C/A
left operand (floating point division)
• Assignment Operators :

\= Divide AND assignment C \= A is equivalent to C =


operator, It divides left C \A
operand with the right
operand and assigns the
result to left operand
(Integer division)
^= Exponentiation and C^=A is equivalent to C =
assignment operator. It C^A
raises the left operand to
the power of the right
operand and assigns the
result to left operand
<<= Left shift AND assignment C <<= 2 is same as C = C
operator << 2
>>= Right shift AND C >>= 2 is same as C = C
assignment operator >> 2
Control Structures
• IF- Statements :
If the condition evaluate to true, then the block
of code inside the if statement will be executed.
If condition evaluates to false, then the first set
of code after the end of the if statement will be
executed.
Control Structures
• IF-ELSE Statements :
IF condition [ then]
[statement]
ELSE [then]
[statement]
Control Structures
• Select Case Statement :
A select case statement allows a variable to be tested for
equality against a list of values. Each variable is called case and
the variable being switched on is checked for each select case.
Syntax :
Select [ case ] expression
[Case expressionList
[ statement ] ]
[ Case Else
[ elsestatements ] ]
End Select
Loops In VB.NET
• For Loop :
It repeats a group of statements a specified
number of times and a loop index counts the
number of loop iterations as the loop executes.
Loops In VB.NET
• While Loop :
It executes a series of statements as long as a
given condition is true.
Syntax :
While condition
[ statements ]
[ Continue While ]
[ statements ]
[ Exit While ]
[ statements ]
End While
Loops In VB.NET
• Do Loop :
It repeats the enclosed block of statements
while a boolean condition is true or until the
condition becomes true. It could be terminated
at any time with the Exit Do statement.
Loops In VB.NET

• For Each Loop :


It repeats a group of statements for each
element in a collection. This loop is used for
accessing and manipulating all elements in an
array or a VB.Net collection.
Syntax:
For Each element [ As datatype ] In group
[ statements ]
[ Continue For ]
[ statements ]
[ Exit For ]
[ statements ]
Next [ element ]
Term Definition

element Required in the For Each statement. Optional in


the Next statement. Variable. Used to iterate through the
elements of the collection.

datatype Required if element isn't already declared. Data type


of element.

Group Required. A variable with a type that's a collection type or


Object. Refers to the collection over which the statements are
to be repeated.

Statements Optional. One or more statements between For


Each and Next that run on each item in group.

Continue For Optional. Transfers control to the start of the For Each loop.

Exit For Optional. Transfers control out of the For Each loop.

Next Required. Terminates the definition of the For Each loop.


Forms Controls in VB.Net And its Properties

• Button :
It is generally used to generate a Click event by providing a
handler for the Click event.
Sr.No. Method Name & Description
1 GetPreferredSize
Retrieves the size of a rectangular area into which a control can be fitted.
2 NotifyDefault
Notifies the Button whether it is the default button so that it can adjust its
appearance accordingly.
3 Select
Activates the control.
4 ToString
Returns a String containing the name of the Component, if any. This method
should not be overridden.
Events of Button Control
Sr.No. Event & Description
1 Click
Occurs when the control is clicked.
2 DoubleClick
Occurs when the user double-clicks the Button control.
3 GotFocus
Occurs when the control receives focus.
4 TabIndexChanged
Occurs when the TabIndex property value changes.
5 TextChanged
Occurs when the Text property value changes.
6 Validated
Occurs when the control is finished validating.
• Text Box :
Text box controls allow entering text on a form at runtime. By default, it takes a single
line of text, however, you can make it accept multiple texts and even add scroll bars to
it.

Sr.No. Method Name & Description


1 AppendText
Appends text to the current text of a text box.
2 Clear
Clears all text from the text box control.
3 Copy
Copies the current selection in the text box to the Clipboard.
4 Cut
Moves the current selection in the text box to the Clipboard.
5 Paste
Replaces the current selection in the text box with the contents of the Clipboard.
7 ResetText
Resets the Text property to its default value.
8 ToString
Returns a string that represents the TextBoxBase control.
Events Of Text box Control
Sr.No. Event & Description
1 Click
Occurs when the control is clicked.
2 DoubleClick
Occurs when the control is double-clicked.
3 TextAlignChanged
Occurs when the TextAlign property value changes.
• Label :
The Label control represents a standard Windows label. It is
generally used to display some informative text on the GUI which
is not changed during runtime.

Sr.No. Method Name & Description


1 GetPreferredSize
Retrieves the size of a rectangular area into which a control can be fitted.
2 Refresh
Forces the control to invalidate its client area and immediately redraw itself
and any child controls.
3 Select
Activates the control.
4 Show
Displays the control to the user.
5 ToString
Returns a String that contains the name of the control.
Events of Label Control
Sr.No. Event & Description
1 AutoSizeChanged
Occurs when the value of the AutoSize property changes.
2 Click
Occurs when the control is clicked.
3 DoubleClick
Occurs when the control is double-clicked.
4 GotFocus
Occurs when the control receives focus.
5 Leave
Occurs when the input focus leaves the control.
6 LostFocus
Occurs when the control loses focus.
7 TabIndexChanged
Occurs when the TabIndex property value changes.
8 TabStopChanged
Occurs when the TabStop property changes.
• Radio Button :
• The RadioButton control is used to provide a set
of mutually exclusive options. The user can select
one radio button in a group. If you need to place
more than one group of radio buttons in the same
form, you should place them in different
container controls like a GroupBox control.

Sr.No. Method Name & Description


1 PerformClick
Generates a Click event for the control, simulating a click by a
user.
Events Of Radio Button Control
Sr.No Event & Description
1 AppearanceChanged
Occurs when the value of the Appearance property of the RadioButton
control is changed.
2 CheckedChanged
Occurs when the value of the Checked property of the RadioButton control
is changed.
• Check box :
The CheckBox control allows the user to set true/false
or yes/no type options. The user can select or deselect
it. 

Sr.No. Method Name & Description


1 OnCheckedChanged
Raises the CheckedChanged event.
2 OnCheckStateChanged
Raises the CheckStateChanged event.
3 OnClick
Raises the OnClick event.
Events Of CheckBox Control
Sr.No. Event & Description
1 AppearanceChanged
Occurs when the value of the Appearance property of the check box is
changed.
2 CheckedChanged
Occurs when the value of the Checked property of the CheckBox control
is changed.
3 CheckStateChanged
Occurs when the value of the CheckState property of the CheckBox
control is changed.
• List Box :
The ListBox represents a Windows control to
display a list of items to a user. A user can select
an item from the list. 

Sr.No. Event & Description


1 Click
Occurs when a list box is selected.
2 SelectedIndexChanged
Occurs when the SelectedIndex property of a list box is
changed.
• Combo Box :
The ComboBox control is used to display a drop- down list of
various items.

Sr.No. Method Name & Description


1 BeginUpdate
Prevents the control from drawing until the EndUpdate method is
called, while items are added to the combo box one at a time.
2 EndUpdate
Resumes drawing of a combo box, after it was turned off by the
BeginUpdate method.
3 FindString
Finds the first item in the combo box that starts with the string
specified as an argument.
4 FindStringExact
Finds the first item in the combo box that exactly matches the specified
string.
5 SelectAll
Selects all the text in the editable area of the combo box.
• Picture Box :
The PictureBox control is used for displaying images on
the form. The Image property of the control allows you
to set an image both at design time or at run time.
Sr.No. Method Name & Description
1 CancelAsync
Cancels an asynchronous image load.
2 Load
Displays an image in the picture box
3 LoadAsync
Loads image asynchronously.
4 ToString
Returns the string that represents the current picture box.
• Panel :
The Panel control is a container control that is used to
host a group of similar child controls. One of the major
uses I found for a Panel control when you have to show
and hide a group of controls. Instead of show and hide
individual controls, you can simply hide and show a
single Panel and all child controls.
• TabControl :
The TabControl manages tab pages where each page
may host different child controls. In this article, I will
demonstrate how to create and use a TabControl in
Windows Forms.
• Timer :
Timer Control plays an important role in the Client side
programming and Server side programming, also used
in Windows Services. By using this Timer Control, windows
allow you to control when actions take place without the
interaction of another thread.

Method Name Description


Start This method is used to start the Timer Control.
Stop This method is used to stop the Timer Control.
THANK YOU!!

You might also like