SlideShare a Scribd company logo
1 of 17
Review of the Basics Advanced Visual Basic
Overview You are now in at least your third semester of programming.  In this course, we will be exploring more of Visual Basic.  Before doing so, we should re-familiarize ourselves with the development environment and some of the basic programming topics.
Variables You often have to store values when you perform calculations with Visual Basic. For example, you might want to calculate several values, compare them, and perform different operations on them, depending on the result of the comparison. You have to retain the values if you want to compare them.Variables store values in RAM. A variable has a name (the word that you use to refer to the value that the variable contains). A variable also has a data type (which determines the kind of data that the variable can store). Example: Dim strFirstName As String
Variables Research Question:  What is the difference between a variable and a constant?
Arrays An array is a set of values that are logically related to each other, such as the number of students in each grade in a grammar school. An array allows you to refer to these related values by the same name and to use a number, called an index or subscript, to tell them apart. The individual values are called the elements of the array. They are contiguous from index 0 through the highest index value. Example: Dim strStudentNames(10) As String
Arrays Research Question:  How many elements are in this array? Dim strStudentNames(10) As String
Loops Visual Basic loop structures allow you to run one or more lines of code repetitively. You can repeat the statements in a loop structure until a condition is True, until a condition is False, a specified number of times, or once for each element in a collection.
Loops (while) Use a While...End While structure when you want to repeat a set of statements an indefinite number of times, as long as a condition remains True. Example: Dim counter As Integer = 0  While counter < 3  counter += 1  ‘Insert code to use current value of counter.  End While  MsgBox("While loop ran " & CStr(counter) & " times")
Loops (do) Use a Do...Loop structure when you want to repeat a set of statements an indefinite number of times, until a condition is satisfied. Example: Dim counter As Integer = 0  Dim number As Integer = 10 Do Until number = 100  	number = number * 10  counter += 1  Loop  MsgBox("The loop ran " & counter & " times.")
Loops (for…next) Use a For...Next structure when you want to repeat a set of statements a set number of times. Example: For index As Integer = 1 To 5 Debug.Write(index.ToString & " ")  Next  Debug.WriteLine("") ' Output: 1 2 3 4 5
Loops (for each) Use a For Each...Next loop when you want to repeat a set of statements for each element of a collection or array. Example: Sub BlueBackground(ByValthisFormAs System.Windows.Forms.Form) For Each thisControl As System.Windows.Forms.ControlIn thisForm.Controls thisControl.BackColor= System.Drawing.Color.LightBlue Next thisControl End Sub
Loops Research Question:  What happens when a loop doesn’t end? 			Dim intValue as integer = 1 			Do Until intValue = 2 MessageBox.Show(“you have a problem!”) 			Loop
Decisions Visual Basic lets you test conditions and perform different operations depending on the results of that test. You can test for a condition being true or false, for various values of an expression, or for various exceptions generated when you execute a series of statements.
Decisions (if…then…else) When an If...Then...Else statement is encountered, condition is tested. If condition is True, the statements following Then are executed. If condition is False, each ElseIf statement (if there are any) is evaluated in order. When a True elseifcondition is found, the statements immediately following the associated ElseIf are executed. If no elseifcondition evaluates to True, or if there are no ElseIf statements, the statements following Else are executed. After executing the statements following Then, ElseIf, or Else, execution continues with the statement following End If. Example: Dim count As Integer = 0  Dim message As String  If count = 0 Then  message = "There are no items."  ElseIfcount = 1 Then  message = "There is 1 item."  Else  message = "There are " & count & " items."  End If
Decisions (if…then…else) The Case Else statement is used to introduce the elsestatements to run if no match is found between the testexpression and an expressionlist clause in any of the other Case statements. Although not required, it is a good idea to have a Case Else statement in your Select Case construction to handle unforeseen testexpression values Example: Dim number As Integer = 8  Select Case number  Case 1 To 5  Debug.WriteLine("Between 1 and 5, inclusive") Case 6, 7, 8  Debug.WriteLine("Between 6 and 8, inclusive")  Case 9 To 10  Debug.WriteLine("Equal to 9 or 10")  Case Else  Debug.WriteLine("Not between 1 and 10, inclusive")  End Select
Decisions Research Question:  What is the most efficient way to determine if someone can vote? Consider:  Age = 17 Age = 18 Age = 19
Additional Information For additional information about these topics, please review your text and the links provided in Blackboard.

More Related Content

What's hot

What's hot (19)

Ppt lesson 08
Ppt lesson 08Ppt lesson 08
Ppt lesson 08
 
Ch03
Ch03Ch03
Ch03
 
Ppt lesson 07
Ppt lesson 07Ppt lesson 07
Ppt lesson 07
 
10 array
10 array10 array
10 array
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
 
Ch02
Ch02Ch02
Ch02
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
StandardsandStylesCProgramming
StandardsandStylesCProgrammingStandardsandStylesCProgramming
StandardsandStylesCProgramming
 
Introduction To Programming
Introduction To ProgrammingIntroduction To Programming
Introduction To Programming
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
Operators , Functions and Options in VB.NET
Operators , Functions and Options in VB.NETOperators , Functions and Options in VB.NET
Operators , Functions and Options in VB.NET
 
Enumerated data types
Enumerated data typesEnumerated data types
Enumerated data types
 
Enums in c
Enums in cEnums in c
Enums in c
 
Ch06
Ch06Ch06
Ch06
 
enums
enumsenums
enums
 

Similar to Advanced VB: Review of the basics

VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSSuraj Kumar
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
Software fundamentals
Software fundamentalsSoftware fundamentals
Software fundamentalsSusan Winters
 
Vb6 ch.8-3 cci
Vb6 ch.8-3 cciVb6 ch.8-3 cci
Vb6 ch.8-3 cciFahim Khan
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...Mark Simon
 
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxCMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxmonicafrancis71118
 
The swift programming language
The swift programming languageThe swift programming language
The swift programming languagePardeep Chaudhary
 
Data Structures- Part1 overview and review
Data Structures- Part1 overview and reviewData Structures- Part1 overview and review
Data Structures- Part1 overview and reviewAbdullah Al-hazmy
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoftch samaram
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2ppJ. C.
 

Similar to Advanced VB: Review of the basics (20)

VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 
Sharbani bhattacharya VB Structures
Sharbani bhattacharya VB StructuresSharbani bhattacharya VB Structures
Sharbani bhattacharya VB Structures
 
Software fundamentals
Software fundamentalsSoftware fundamentals
Software fundamentals
 
Vb6 ch.8-3 cci
Vb6 ch.8-3 cciVb6 ch.8-3 cci
Vb6 ch.8-3 cci
 
VB(unit1).pptx
VB(unit1).pptxVB(unit1).pptx
VB(unit1).pptx
 
Java Basics 1.pptx
Java Basics 1.pptxJava Basics 1.pptx
Java Basics 1.pptx
 
M C6java2
M C6java2M C6java2
M C6java2
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
 
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxCMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
 
The swift programming language
The swift programming languageThe swift programming language
The swift programming language
 
Data Structures- Part1 overview and review
Data Structures- Part1 overview and reviewData Structures- Part1 overview and review
Data Structures- Part1 overview and review
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoft
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Perl slid
Perl slidPerl slid
Perl slid
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2pp
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
pythonQuick.pdf
pythonQuick.pdfpythonQuick.pdf
pythonQuick.pdf
 

More from robertbenard

Accessing data within VB Applications
Accessing data within VB ApplicationsAccessing data within VB Applications
Accessing data within VB Applicationsrobertbenard
 
Advanced VB: Object Oriented Programming - Controls
Advanced VB: Object Oriented Programming - ControlsAdvanced VB: Object Oriented Programming - Controls
Advanced VB: Object Oriented Programming - Controlsrobertbenard
 
Advanced VB: Object Oriented Programming - DLLs
Advanced VB: Object Oriented Programming - DLLsAdvanced VB: Object Oriented Programming - DLLs
Advanced VB: Object Oriented Programming - DLLsrobertbenard
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basicsrobertbenard
 
Cascading Style Sheets in Dreamweaver
Cascading Style Sheets in DreamweaverCascading Style Sheets in Dreamweaver
Cascading Style Sheets in Dreamweaverrobertbenard
 
Performance Assessment Task
Performance Assessment TaskPerformance Assessment Task
Performance Assessment Taskrobertbenard
 
Lists, formatting, and images
Lists, formatting, and imagesLists, formatting, and images
Lists, formatting, and imagesrobertbenard
 

More from robertbenard (20)

Sample
SampleSample
Sample
 
Xampe
XampeXampe
Xampe
 
Accessing data within VB Applications
Accessing data within VB ApplicationsAccessing data within VB Applications
Accessing data within VB Applications
 
Advanced VB: Object Oriented Programming - Controls
Advanced VB: Object Oriented Programming - ControlsAdvanced VB: Object Oriented Programming - Controls
Advanced VB: Object Oriented Programming - Controls
 
Advanced VB: Object Oriented Programming - DLLs
Advanced VB: Object Oriented Programming - DLLsAdvanced VB: Object Oriented Programming - DLLs
Advanced VB: Object Oriented Programming - DLLs
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basics
 
Copyright Basics
Copyright BasicsCopyright Basics
Copyright Basics
 
Cascading Style Sheets in Dreamweaver
Cascading Style Sheets in DreamweaverCascading Style Sheets in Dreamweaver
Cascading Style Sheets in Dreamweaver
 
Performance Assessment Task
Performance Assessment TaskPerformance Assessment Task
Performance Assessment Task
 
WIDS Jeopardy
WIDS JeopardyWIDS Jeopardy
WIDS Jeopardy
 
Wids Model
Wids ModelWids Model
Wids Model
 
Lesson 2
Lesson 2Lesson 2
Lesson 2
 
Lists, formatting, and images
Lists, formatting, and imagesLists, formatting, and images
Lists, formatting, and images
 
Lesson 7
Lesson 7Lesson 7
Lesson 7
 
Lesson 6
Lesson 6Lesson 6
Lesson 6
 
Lesson 5
Lesson 5Lesson 5
Lesson 5
 
Lesson 4
Lesson 4Lesson 4
Lesson 4
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
 

Recently uploaded

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 

Recently uploaded (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 

Advanced VB: Review of the basics

  • 1. Review of the Basics Advanced Visual Basic
  • 2. Overview You are now in at least your third semester of programming. In this course, we will be exploring more of Visual Basic. Before doing so, we should re-familiarize ourselves with the development environment and some of the basic programming topics.
  • 3. Variables You often have to store values when you perform calculations with Visual Basic. For example, you might want to calculate several values, compare them, and perform different operations on them, depending on the result of the comparison. You have to retain the values if you want to compare them.Variables store values in RAM. A variable has a name (the word that you use to refer to the value that the variable contains). A variable also has a data type (which determines the kind of data that the variable can store). Example: Dim strFirstName As String
  • 4. Variables Research Question: What is the difference between a variable and a constant?
  • 5. Arrays An array is a set of values that are logically related to each other, such as the number of students in each grade in a grammar school. An array allows you to refer to these related values by the same name and to use a number, called an index or subscript, to tell them apart. The individual values are called the elements of the array. They are contiguous from index 0 through the highest index value. Example: Dim strStudentNames(10) As String
  • 6. Arrays Research Question: How many elements are in this array? Dim strStudentNames(10) As String
  • 7. Loops Visual Basic loop structures allow you to run one or more lines of code repetitively. You can repeat the statements in a loop structure until a condition is True, until a condition is False, a specified number of times, or once for each element in a collection.
  • 8. Loops (while) Use a While...End While structure when you want to repeat a set of statements an indefinite number of times, as long as a condition remains True. Example: Dim counter As Integer = 0 While counter < 3 counter += 1 ‘Insert code to use current value of counter. End While MsgBox("While loop ran " & CStr(counter) & " times")
  • 9. Loops (do) Use a Do...Loop structure when you want to repeat a set of statements an indefinite number of times, until a condition is satisfied. Example: Dim counter As Integer = 0 Dim number As Integer = 10 Do Until number = 100 number = number * 10 counter += 1 Loop MsgBox("The loop ran " & counter & " times.")
  • 10. Loops (for…next) Use a For...Next structure when you want to repeat a set of statements a set number of times. Example: For index As Integer = 1 To 5 Debug.Write(index.ToString & " ") Next Debug.WriteLine("") ' Output: 1 2 3 4 5
  • 11. Loops (for each) Use a For Each...Next loop when you want to repeat a set of statements for each element of a collection or array. Example: Sub BlueBackground(ByValthisFormAs System.Windows.Forms.Form) For Each thisControl As System.Windows.Forms.ControlIn thisForm.Controls thisControl.BackColor= System.Drawing.Color.LightBlue Next thisControl End Sub
  • 12. Loops Research Question: What happens when a loop doesn’t end? Dim intValue as integer = 1 Do Until intValue = 2 MessageBox.Show(“you have a problem!”) Loop
  • 13. Decisions Visual Basic lets you test conditions and perform different operations depending on the results of that test. You can test for a condition being true or false, for various values of an expression, or for various exceptions generated when you execute a series of statements.
  • 14. Decisions (if…then…else) When an If...Then...Else statement is encountered, condition is tested. If condition is True, the statements following Then are executed. If condition is False, each ElseIf statement (if there are any) is evaluated in order. When a True elseifcondition is found, the statements immediately following the associated ElseIf are executed. If no elseifcondition evaluates to True, or if there are no ElseIf statements, the statements following Else are executed. After executing the statements following Then, ElseIf, or Else, execution continues with the statement following End If. Example: Dim count As Integer = 0 Dim message As String If count = 0 Then message = "There are no items." ElseIfcount = 1 Then message = "There is 1 item." Else message = "There are " & count & " items." End If
  • 15. Decisions (if…then…else) The Case Else statement is used to introduce the elsestatements to run if no match is found between the testexpression and an expressionlist clause in any of the other Case statements. Although not required, it is a good idea to have a Case Else statement in your Select Case construction to handle unforeseen testexpression values Example: Dim number As Integer = 8 Select Case number Case 1 To 5 Debug.WriteLine("Between 1 and 5, inclusive") Case 6, 7, 8 Debug.WriteLine("Between 6 and 8, inclusive") Case 9 To 10 Debug.WriteLine("Equal to 9 or 10") Case Else Debug.WriteLine("Not between 1 and 10, inclusive") End Select
  • 16. Decisions Research Question: What is the most efficient way to determine if someone can vote? Consider: Age = 17 Age = 18 Age = 19
  • 17. Additional Information For additional information about these topics, please review your text and the links provided in Blackboard.