Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
មេរៀនទី ៣៖ Control flow statement of VB.NET
1. Norton University Lesson 3 Subject ៖ VB.NET
Academic year: 2014-2015 Page 1 Lecturer: Msc OU Bundeth
មេម ៀនទី ៣៖ Control Flow Statement
មៅក្នុងមេម ៀនមនេះមយើងនឹងម ើក្យក្ពីកា ម្រើ្ាស់ Control Structure មៅក្នុងភាសា VB.NET ។ មៅក្នុងចំណុច Control Structure មនេះ្រូវានបរងបចក្មចញជាពី គឺ Select Structure និង Loop ។
Select Structure មានដូចជា៖
- If Statement
- Select Statement
- Ternary
Loop មានដូចជា៖
- For Loop
- Do While|Until loop Statements
- Do loop While|Until Statements
- While End While
- For Each
1. Select Structure
មគម្រើ Select Structure មដើេបីម្វើកា សិក្ា ក្ខខណឌេួយ ឬម្ចើនមៅតាេ Expression និងValues បដ មយើងមាន ដូចជា៖ កា សិក្ាមៅម ើពិនទុសិសស េ្យេភាគ ឬ ក្ំ ិរននកា គណនាណាេួយបដ ជាមោ កា ណ៍នន្ក្ុេហ ុន ឬសាារ័នមយើងក្ំណរ់ ្ពេទំង អាចជាចារ់ក្បួន ខ្ននរអវីេួយ ជាមដើេ ។
មៅក្នុង Select Structure មនេះបដ ្រូវានបរងបចក្ជារី គឺ ៖
- IF Statement
- Select Statement
- IIF Statement(Ternary)
មនេះជា Process នន Select Statement ៖
1.1 If Statement
មយើងម្រើវាមដើេបីសិក្ា ក្ខខណឌបរអាចមាន ទធភាពពិរ ឬ េិនពិរមៅតាេ ក្ខខណឌ រស់ If ។
Syntax: If condition Then
statements
End If
Ex: Dim LName As String = "Dara"
If LName=”Dara” Then
MessageBox.Show("True")
2. Norton University Lesson 3 Subject ៖ VB.NET
Academic year: 2014-2015 Page 2 Lecturer: Msc OU Bundeth
End If
1.2 If Else
មយើងម្រើ If Else មដើេបីសិក្ា ក្ខខណឌបរ ក្ខខណឌ មនាេះ្រូវបរេួយពិរជានិចចមរើ Block If ក្ខខណឌ មនាេះ Block Else នឹងេិនម្វើកា មឡើយបរមរើ Block If េិនពិរមនាេះវា និងម្វើកា Block Else ភាាេ មោយេិនាច់ពិរ ក្ខខណឌ ។
Syntax: If conditions Then
statements
Else
statements
End If
Ex: Dim Score as integer=10
If i>=5 Then
MessageBox.Show(“Pass")
Else
MessageBox.Show(“Fall")
End If
1.3 If ElseIf Else
មយើងម្រើវាមដើេបីសិក្ា ក្ខខណឌម្ចើន បរ ក្ខខណឌមនាេះមានបរេួយមទបដ ពិរ មរើ Block If ម្វើកា មនាេះ Block Else If និង Else េិនម្វើកា មទ បរមរើ Block If េិនពិរមនាេះវានឹង្រួរពិនិរយ Block Else If មរើពិរវាេិនម្វើកា Block Else
បរមរើ ក្ខខណឌទំងពី ខ្នងម ើេិនពិរវានឹងម្វើកា Block Else ។
Syntax: If conditions Then
statements
Else If conditions Then
statements
Else
statements
End If
Ex: Dim score as integer=55
If score = 50 Then
MessageBox.Show(“Fair”)
Else If score <50 Then
MessageBox.Show(“Fall”)
Else
MessageBox.Show(“Good”)
End If
1.4 Select Case
មយើងម្រើ Select case មដើេបីសិក្ា ក្ខខណឌ ដូចមៅនិង If បដ បរវាមាន Expression បរេួយ ។
a. syntax 1
Select case expression
case value1
Statements
3. Norton University Lesson 3 Subject ៖ VB.NET
Academic year: 2014-2015 Page 3 Lecturer: Msc OU Bundeth
case value2
Statements
case value3
Statements
case else
Statements
End Select
b. Syntax 2
Select case expression
case is value1
Statements
case is value2
Statements
case is value3
Statements
case else
Statements
End select
c. Syntax 3
select case condition
case value1 to value2
Statements
case value3 to value3
Statements
case value5 to value6
Statements
case else
Statements
End select
d. Syntax 4
Select case expression
case value1, value2
Statements
case value3, value4
Statements
case value5, value6
Statements
case else
Statements
End select
4. Norton University Lesson 3 Subject ៖ VB.NET
Academic year: 2014-2015 Page 4 Lecturer: Msc OU Bundeth
1.5 Ternary
មគម្រើ ternary ស្មារ់ម្វើកា សិក្ា ក្ខខណឌ មៅម ើ Inline Statement បដ អាចផ្ត ់ជម្េើសឱ្យមយើង True ឬ False ។
Syntax:
IIF(Condition,True,False) ឬ
IF(Condition,True,False)
Example:
Dim Average As Single=60
MsgBox(IIF(Average>=50,”Passed”,”Falled”))
Example:
- Student Grade
- Tax Salary
- Water and Electric Calculate
2 Loop Statement
មយើងម្រើ loop មដើេបីមអាយ Program ដំមណើ កា ដបដ មៅតាេចំនួនដងបដ មយើងានក្ំណរ់ ។
2.1 For Loop
Syntax: For variable= start To end [step num]
statements
Next [variable]
Ex: Dim i as integer=0
For i=0 To 3 step 1
MessageBox.Show(i.ToString())
Next
2.2 Do While|Until loop Statements
Syntax: Do {While|Until} Condition
Statements
Loop
Example1:
Dim index As Integer=10
Do While Index<=15
Index+=1
MessageBox.Show(Index)
Loop
Output: 11,12,13,14,15,16
5. Norton University Lesson 3 Subject ៖ VB.NET
Academic year: 2014-2015 Page 5 Lecturer: Msc OU Bundeth
Example2:
Dim index As Integer=10
Do Until Index>=15
Index+=1
MessageBox.Show(Index)
Loop
Output: 11,12,13,14,15
2.3 Do loop While|Until Statements
Syntax: Do
Statements
Loop {While|Until} Condition
Example1:
Dim index As Integer=10
Do
Index+=1
MessageBox.Show(Index)
Loop While Index<=15
Output: 11,12,13,14,15,16
Example2:
Dim index As Integer=10
Do
Index+=1
MessageBox.Show(Index)
Loop Until Index>=15
Output: 11,12,13,14,15
2.4 While End While
Syntax: While Condition
Statements
End While
Example:
Dim Index As Integer=10
While Index<=0
Index +=1
MessageBox.Show(Index)
End While
2.5 For Each
Syntax: For Each item In Collection
Statements
Next
Ex: Dim txt as Controls
6. Norton University Lesson 3 Subject ៖ VB.NET
Academic year: 2014-2015 Page 6 Lecturer: Msc OU Bundeth
For Each txt in Me.controls
If Type of txt is TextBox
txt.Text=“”
End If
Next
Exercise:
- N!=1*2*3*4*....*n
- Sn=1+2+3+4...+n
- Sn=2+4+6+8...+2n
- Sn=1+3+5+7...+(2n-1)
- Sn=12+22+32+...+n2
- Sn=1+1/2+1/3+...1/n
- Sn=1!+2!+3!+...+n!
- Table of Multiple
- Change Keyboard Khmer and English
- Enter to Next Control
- Loop Control to Clear Data