decision statements in vb.net

12
DECISION STATEMENTS IN VB.NET

Upload: ilakkiya

Post on 22-Apr-2015

6.276 views

Category:

Education


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Decision statements in vb.net

DECISION STATEMENTSIN

VB.NET

Page 2: Decision statements in vb.net

Introduction

• Decision making statements in VB.NET are used to

control the flow of a program by checking one or more

conditions. There are 3 types, They are

– If … then

– If …. Then … else

– Select case

Page 3: Decision statements in vb.net

If .. then

• This statement is used to test a condition and execute

a set of statements if the condition is true . If it is

false, the statement which is next to the if … then

structure is executed.

Page 4: Decision statements in vb.net

syntax

If Condition Then    One or more Visual Basic statementsEnd If

Page 5: Decision statements in vb.net

Example

Dim mark as integer

If mark>40 then

Msgbox (“Pass”)

End if

Page 6: Decision statements in vb.net

If … then … else

• This statement is used to test a condition and

execute a set of statements if the condition is

true and execute another set of statement if it

is false.

Page 7: Decision statements in vb.net

Syntax

If condition Then

  One or more statements

Else

  One or more statements

End If

Page 8: Decision statements in vb.net

Example

• Dim a As Integer

Dim b As Integer

a = 3

b = 4

If a > b Then

    MsgBox ("a is greater then b")

Else

    MsgBox ("b is greater then a")

End If

Page 9: Decision statements in vb.net

Select case statement

• The Select Case statement executes one of several

groups of statements depending on the value of an

expression. If your code has the capability to handle

different values of a particular variable then you can

use a Select Case statement. You use Select Case to

test an expression, determine which of the given cases

it matches and execute the code in that matched case.

Page 10: Decision statements in vb.net

Syntax • Select Case expression

   Case value1

        Statement 1

   Case value2

        Statement 2

   Case value3

      Statement 3

   Case value4

        .

        .

        .

   Case Else

        Statement

End Select

Page 11: Decision statements in vb.net

Example • ' Examination Grades

Dim grade As String Private Sub Compute_Click( )     grade= txtgrade.Text     Select Case grade       Case  "A"            result.Caption="High Distinction"       Case "A-"           result.Caption="Distinction"       Case "B"             result.Caption="Credit"       Case "C"             result.Caption="Pass"       Case Else             result.Caption="Fail"       End Select End Sub

Page 12: Decision statements in vb.net

The End.

… Thank u…