SlideShare a Scribd company logo
1 of 6
Download to read offline
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")
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
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
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
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
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

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
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