If Else .. Select Case in VB.NET

1,684 views 17 slides Mar 22, 2014
Slide 1
Slide 1 of 17
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17

About This Presentation

VB.NET


Slide Content

. NET Decision making 1 Shyam N. Chawda +91 78 74 39 11 91

Control Statements It’s decide the flow of program 2 types Branching statements, Test Structure, Decision Structure Loop statements 2 Shyam N. Chawda 9374928879

Control Statements Branching Statements If , Select case Loop Statements For,Do,While 3 Shyam N. Chawda 9374928879

Syntax – If..else If condition Then Logic… End if If condition Then Logic… Else Logic…. End if If condition Then Logic… ElseIf condition-n Then Logic.. Else Logic… End If 4 Shyam N. Chawda 9374928879

If TotalMarks>150 then Logic.. End if If a=b then Logic.. Else Logic.. End if If Marks>0 and Marks<50 then Logic.. Else if Marks>=50 and Marks<100 then Logic.. Else if Marks>=100 and Marks<150 then Logic.. End if 5 Shyam N. Chawda 9374928879

If..else if..else..Then When it finds a True condition Else statement block, which Visual Basic.net executes if none of the conditions are True. You can have any number of ElseIf 6 Shyam N. Chawda 9374928879

If..else if..else..Then You can use And / Or condition with it . Example : If marks>50 and marks<100 then statements Else if marks>=100 and marks<150 then statements End if 7 Shyam N. Chawda 9374928879

Exercise Leap Year Odd,Even Positive , Negative Maximum,Minimum number Mark of students Between 0 - 50,50 –100 ,100-150 8 Shyam N. Chawda 9374928879

Select Case Whereas the If and ElseIf statements can evaluate a different expression in each statement, The Select statement evaluates a single expression only once and uses it for every comparison. 9 Shyam N. Chawda 9374928879

Syntax – Select Case Select Case testexpression [Case expressionlist -n [statements-n]] ... [Case Else [ elsestatements ]] End Select 10 Shyam N. Chawda 9374928879

Example-1 Select Performance Case 1 ' Performance is 1. Return Salary * 0.1 Case 2, 3 ' Performance is 2 or 3. Return Salary * 0.09 Case 5 To 7 ' Performance is 5, 6, or 7. Return Salary * 0.07 11 Shyam N. Chawda 9374928879

Example-1 Case 4, 8 To 10 ‘Performance is 4, 8, 9, or 10. Return Salary * 0.05 Case Is < 14 'Performance is 11, 12, 13. Return 100 Case Else ' Performance is < 1 or > 14. Return 0 End select 12 Shyam N. Chawda 9374928879

Example-2 Select Case JobPlace Case “Ahmedabad” logic… Case “ Mumbai”,”Delhi”,”Chennai ” logic.. Case Else logic.. End select 13 Shyam N. Chawda 9374928879

Select…Case If multiple Case statements are True, only the statements belonging to the first true Case statement are executed. Case Else clause must be the last Case clause. 14 Shyam N. Chawda 9374928879

Select…Case Use the To keyword to specify a range of values. The Is keyword is used to precede any comparison operators. 15 Shyam N. Chawda 9374928879

Exercise Enter Color name and according to it textbox color will change Enter student no according to no display message “ Good”,”Try best in next exam”,”Need to improve” 16 Shyam N. Chawda 9374928879

Thanks Any questions ? www.shyamsir.com Shyam N. Chawda 9374928879 17