You are on page 1of 6

SELECT...

CASE SELECTION STRUCTURE

Select...Case structure is an alternative to If...Then...ElseIf for selectively


executing a single block of statements from among multiple block of
statements.
Select...case is more convenient to use than the If...Else...End If. The
following program block illustrate the working of Select...Case.

Syntax of the Select...Case selection structure


Select Case <expression>
Case 0
Statements
Case 1
Statements
End Select
e.g.: Assume you have to find the grade using select...case and display in the
text box
Dim average as Integer

average = val(txtAverage.Text)
Select Case average
Case 100 To 75
txtGrade.Text ="A" Select Case <expression>
Case 74 To 65 Case 0
txtGrade.Text ="B" Statements
Case 1
Case 64 To 55 Statements
txtGrade.Text ="C" End Select
Case 54 To 45
txtGrade.Text ="S"
Case 44 To 0
txtGrade.Text ="F"
Case Else
MsgBox "Invalid average marks"
End Select
Example Program :

Private Sub Form_Activete()


Dim intmark As Integer
Intmark=InputBox(“Enter your mark : “)
Select Case Intmark
Case 80 to 100
Print “Good”
Case 50 to 79
Print “Moderate”
Case Is < 50
Print “ Fail”
Case Else
Print “Invalid”
End Select
Select case txtTeamname.text
case “tiger”
Print “Tiger”
case “Cougars”, “Panthers”
Print “Cougars and Panthers”
case “Leopard”
Print “Leopard”
end select
Select Case byMonth
Case 1,3,5,7,8,10,12
number_of_days=31
Case 2
number_of_days=28
Case 4,6,9,11
number_of_days=30
End Select
Left , Right and Mid Function

1. Left (txtName.text , 5) ‘ Returns first 5 characters


2. Right (txtName.text , 1) ‘ Returns last 1 character
3. Mid (txtName.text , 4) ‘ Returns all characters beginning with character 4
4. Right (txtName.text , 4,3) ‘ Returns 3 characters beginning with character 4
5. len (txtName.text) ‘ Return the number of character in the text box

If txtName.text = “Zainal Fikri”

The output
1. Zainal
2. i
3. Nal Fikri
4. Nal
5. 12

You might also like