0% found this document useful (0 votes)
2 views

select-case (2)

The document explains the usage of If…Then…ElseIf statements and Select Case statements in Visual Basic 2022 for creating conditional logic. It provides syntax examples and illustrates how to implement multiple conditions and cases for decision-making based on variable values. Additionally, it highlights the use of comparison operators and expression lists in the Select Case structure.

Uploaded by

arnoldvizon001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

select-case (2)

The document explains the usage of If…Then…ElseIf statements and Select Case statements in Visual Basic 2022 for creating conditional logic. It provides syntax examples and illustrates how to implement multiple conditions and cases for decision-making based on variable values. Additionally, it highlights the use of comparison operators and expression lists in the Select Case structure.

Uploaded by

arnoldvizon001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

If…Then…ElseIf statement

used in circumstances where there are more than


two(2) alternative conditions.
Syntax:
If condition (Then)
(VB2022 expression 1)
ElseIf condition Then
(VB2022 expression 2)
ElseIf condition Then
(VB2022 expression3)
Else
(VB2022 expression 4)
End If
 If-Then-ElseIf syntax is used to create conditional
statements with multiple conditions.
as long as condition1 is TRUE, then one set of
statements will be executed, and when condition2
is TRUE, another set will be executed
Dim Number as Integer
Dim Echo as String
Number= Txt1.Text
Echo=Lbl3.Text
If Number <=10 Then
Lbl3.Text = “Have a good morning ”
ElseIf Number<=20
Lbl3.Text= “Have a good day”
Else
Lbl3.Text= “Have a good night”
End If
Select Case statement allows a variable to be tested
for equality against a list of values
 Each value is referred to as a case

Syntax
Select [ Case ] expression
[ Case expressionlist
[ statements ] ]
[ Case Else
[ elsestatements ] ]
End Select
Where:
•expression: Represents an expression that must
evaluate to any of the data types (selector)
•expressionlist: Denotes a list of expression clauses
representing match values for the expression. Multiple
expression clauses are separated by commas.
•statements: Refers to the statements
following Case that run if the select expression
matches any clause in the expressionlist.
•Case Else: Represents the block of one or more VB
statements to be executed if the select expression
does not match any of the specified cases.
•expressionlist: Each clause can take one of the
following forms:
- expression1 To expression2
- [ Is ] comparisonoperator expression
- expression

Use the To keyword to specify the boundaries of a range


of match values for testexpression. The value
of expression1 must be less than or equal to the value
of expression2.

Use the Is keyword with a comparison operator


(=, <>, <, <=, >, or >=) to specify a restriction on the
match values for testexpression. If the Is keyword is not
•expressionlist:

The form specifying only expression is treated as a


special case of the Is form
where comparisonoperator is the equal sign (=). This
form is evaluated as testexpression = expression.

The expressions in expressionlist can be of any data


type, provided they are implicitly convertible to the
type of testexpression and the
appropriate comparisonoperator is valid for the two
types it is being used with.
Dim grade As String
grade =Txt1.text
Case "A"
Txt2.Text="High Distinction"
Case "A-"
Txt2.Text= “Distinction"
Case "B"
Txt2.Text= “Credit"
Case "C"
Txt2.Text= “Pass”
Case Else
Txt2.Text=“Fail”
End Select
End Sub
Dim age As Integer
age = Txt1.Text
Select Case age
Case Is < 17
Txt2.Text=“You are not old enough to drink alcohol"
Case Is >= 18
Txt2.Text=“You are old enough to drink alcohol, but
drink carefully!"
Case Else
Txt2.Text=“Didn't understand that”
End Select
Dim age As Integer
age = Txt1.Text
Select Case age
Case 10 To 17
Txt2.Text=“You are not old enough to drink alcohol"
Case 18 To 50
Txt2.Text="You are old enough to drink alcohol, but drink
carefully!”
Case Else
Txt2.Text=“Didn't understand that”
End Select

You might also like