Title: Microsoft Visual Basic 'NET Language
1MicrosoftVisual Basic .NETLanguage 2
2Flow-Control Statements
- If End If
- Select Case End Select
- For Next
- Do Loop
- Exit
3If End If
If Condition Then End If
Example If Scoregt80 Then Result
"A" ElseIf Scoregt50 Then Result "B" Else
Result "F" End If
If Condition Then Else End If
If Condition1 Then ElseIf Condition2
Then End If
4Select Case End Select
Select Case Expression Case value1 Case
value2 . . . Case Else End Select
Example Select Case Score Case 80 To
100 Result "A" Case 70 To 79 Result
"B" Case 60 To 69 Result "C" Case
Else Result "F" End Select
5Example IfThenElse, SelectCase
Example SelectCase Select Case Score Case 80
To 100 Result "A" Case 70 To 79 Result
"B" Case 60 To 69 Result "C" Case
Else Result "F" End Select
Example IfThenCase If Scoregt80 Then
Result "A" ElseIf Scoregt50 Then Result
"B" Else Result "F" End If
6Example 1
7For Next
For Counter Start To End Next -------
-----------or-------------------- For Counter
As Integer Start To End Next
Example1 Dim Result As Integer 0 Dim I As
Integer For I 1 To 5 Result I Next MsgBox
(Result I)
Example2 Dim Result As Integer 0 For I As
Integer 1 To 5 Result I Next MsgBox
(Result I)
8Do Loop
Do While/Until Condition Loop
Do Loop While/Until Condition
Example1 Dim Result As Integer 0 Dim I As
Integer 0 Do Until Igt2 I 1 Result
I Loop MsgBox (Result I)
Example2 Dim Result As Integer 0 Dim I As
Integer 0 Do While I lt 2 I 1 Result
I Loop MsgBox (Result I)
9Exit
- Exit from block of statements in a control
structure.
Example Dim I As Integer 0 Dim Result As
Integer 0 Do Until Igt4 I 1 Result I If
Resultgt5 Then Exit Do End If Loop MessageBox.Sh
ow (Result I)
10Sub
Scope Sub name(param1) End Sub
Public Sub SayHello() MessageBox.Show ("Hello
World") End Sub
Public Sub SayHello(ByVal Name As String)
MessageBox.Show ("Hello " Name) End Sub
Call SayHello("Peter")
11Function
Scope Function name(param1) As Type End
Sub
Public Function Add() As Integer Return 0 End Sub
Public Function Add(ByVal Val1 As Integer, ByVal
Val2 As Integer) As Integer Return Val1Val2 End
Sub
A Add( 3 , 4 )