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

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 

Recently uploaded (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 

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.