CCP503

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 26

DEPARTMENT OF TECHNICAL EDUCATION

ANDHRAPRADESH

Name : K.Sreeramacharyulu
Designation : Lecturer
Branch : Commercial and Computer Practicee
Institute : Govt Polytechnic, Srikakulam
Year/Semester : V Semester
Subject : VISUAL BASIC-I
Sub. Code : CCP-503
Topic : Programming Fundamentals
Duration : 50 Mts
Sub. Topic : Decision control structures
Teaching Aids : PPT, Clips and Images
CCP503.33 1
Objective:
On completion of this period, you would be able to
know :

 Concept of Decision control flow statements


 Writing small programs by using Decision
control flow statements – like If….End if,
Select.. Case etc,.

CCP503.33 2
Recap

 Looping constructs
 Do…while
 For…Next
 While…Wend

CCP503.33 3
Decision Constructs

Decision constructs help in testing values with


Relational and Logical expressions and change
the flow of program execution based on the
results of testing
 If…Then
 If…Then…Else
 Select Case

CCP503.33 4
General Syntax Of Simple If
 If <Condition> then
Executable Statement
End if
 Condition is a Relational or Logical expression
 Execute statements with If…End if , if the
condition tests ‘True’
Example:
If (age>=18) then
Msgbox(“ You are eligible to Vote”);
end if
CCP503.33 5
Program 1 on If…Then (Simple if)

Follow the steps to develop application:

 Open a new Standard EXE project in design


mode

 Change its name as Form1

 Double-click on Form itself and enter code in


form_click as in Fig 32.1

CCP503.33 6
The program asks a number is greater than ‘0’,
it doubles it and shows the result

Fig 33.1
CCP503.33 7
Program 2 on If…Then…Else If

Follow the steps to develop application:

 Open a new Standard EXE project in design mode

 Change its name as Form1 and its caption as “If…


Then…Else”

 Place a command button , change its caption as


“InputScore” & name as “Exit”

 Double-click on command buttons & enter code as in


Fig33.2

CCP503.33 8
Fig 33.2
CCP503.33 9
Program 3 on If…Then…Else
Follow the steps to develop application:

 Open a new Standard EXE project in design mode

 Change its name as Form1

 Double-click on Form itself and enter code in


form_click

 Now run application, click anywhere on form while


running

 Observe changes as in Fig 33.3


CCP503.33 10
Fig 33.3
CCP503.33 11
Select…Case

 This construct is similar to If…Else…Then but


much more simple
 It also helps in carrying out different operations
for different values of a variable

CCP503.33 12
Select…Case (Contd..)
 Its construct is
Select Case Variable
Case value1
Statements
Case value2
Statements
Case Else
Statement when none of the above
conditions are satisfied
End Select

CCP503.33 13
Program 4 on Select…Case
Follow the steps to develop application:

 Open a new Standard EXE project in design


mode

 Change its name as Form1

 Add two buttons ”choose color” , ”exit”

 Now run application, & click “choose color”

 Observe changes as in Fig 33.4


CCP503.33 14
Fig 33.4
CCP503.33 15
Program 5 on Select…Case

Follow the steps to develop application:

 Open a new Standard EXE project & name it as


Form1

 Add two buttons ”compute” , ”exit” and one text


and two label boxes as in Fig 33.5

 Now run application & click “compute”

 Observe changes as in Fig 33.5

CCP503.33 16
Fig 33.5
CCP503.33 17
Program 6 on Select…Case

Follow the steps to develop application:

 Open a new Standard EXE project & name it as


Form1

 Add two buttons ”compute” , ”exit” and one text


and two label boxes as in Fig 33.6

 Now run application, & click “compute”

 Observe changes as in Fig 33.6

CCP503.33 18
Fig 33.6
CCP503.33 19
Program 7 on Select…Case
Follow the steps to develop application:

 Open a new Standard EXE project & name it as


Form1

 Add two buttons ”compute” , ”exit” and one text


and two label boxes as in Fig 33.7

 Now run application, & click “compute”

 Observe changes as in Fig 33.7

CCP503.33 20
Fig 33.7
CCP503.33 21
Summary

 The concept of Decision Control Structures


 Their general syntax
 Sample programs on Decision Control Flow
Structures

CCP503.33 22
Frequently Asked Questions

1. List and explain the Control Flow Statements in VB


with examples of each?
2. Write syntax of different types of IF statements in VB?
Use examples to explain?
3. Explain Select…Case statement, with a small menu
driven program as an example?

CCP503.33 23
QUIZ

1. Which of the following is NOT a decision


making statement?

A. For … Next
B. IF … then….End if
C. Select …. Case
D. If … then … Else….end if

CCP503.33 24
2. Dim grade As String
Private Sub Compute_Click( )
grade=Input Box (“Enter grade as like (A/B/C): ”)
Select Case grade
Case "A"
Txtresult .Caption="Distinction"
Case “B"
Txtresult .Caption=“First Class"
Case “C”
Txtresult. Caption=“Pass”
Case Else
Txtresult .Caption="Fail"
End Select
In the above program, If grade is ” A” , what will be the
result?
a) Distinction
b) Pass
c) Fail
d) First Class
CCP503.33 25
Assignment

1. Does every If statement requires code in its


code block area?
2. In a Select statement, how many times is the
expression that is being compared to the
different cases evaluated?
3. Write a program that takes marks of a student
in 3 subjects and calculate their sum if they are
all above 35 and shows the total

CCP503.33 26

You might also like