SlideShare a Scribd company logo
Review of the BasicsAdvanced Visual Basic
OverviewYou 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.
VariablesYou 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
VariablesResearch Question: What is the difference between a variable and a constant?
ArraysAn 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
ArraysResearch Question: How many elements are in this array?Dim strStudentNames(10) As String
LoopsVisual 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 = 10Do 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.ControlsthisControl.BackColor= System.Drawing.Color.LightBlueNext thisControlEnd Sub
LoopsResearch Question: What happens when a loop doesn’t end?			Dim intValue as integer = 1			Do Until intValue = 2MessageBox.Show(“you have a problem!”)			Loop
DecisionsVisual 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 valuesExample: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
DecisionsResearch Question: What is the most efficient way to determine if someone can vote?Consider: Age = 17Age = 18Age = 19
Additional InformationFor additional information about these topics, please review your text and the links provided in Blackboard.

More Related Content

PPTX
Vb decision making statements
PPTX
Conditional statements
PPTX
PPTX
FUNDAMENTAL OF C
DOCX
Data types and operators in vb
PPTX
Introduction To Programming with Python-1
PDF
Computer
Vb decision making statements
Conditional statements
FUNDAMENTAL OF C
Data types and operators in vb
Introduction To Programming with Python-1
Computer

What's hot (19)

PPT
Ppt lesson 08
PPT
Ppt lesson 07
PPT
PPTX
Structures in c language
PDF
[ITP - Lecture 04] Variables and Constants in C/C++
PPTX
Cpu-fundamental of C
PPTX
Introduction To Programming with Python Lecture 2
DOC
Pseudocode
PPT
StandardsandStylesCProgramming
PPT
Introduction To Programming
PPT
Getting started with c++
PPTX
arrays and pointers
PPTX
Operators , Functions and Options in VB.NET
PPTX
Enumerated data types
PPTX
PPT
enums
Ppt lesson 08
Ppt lesson 07
Structures in c language
[ITP - Lecture 04] Variables and Constants in C/C++
Cpu-fundamental of C
Introduction To Programming with Python Lecture 2
Pseudocode
StandardsandStylesCProgramming
Introduction To Programming
Getting started with c++
arrays and pointers
Operators , Functions and Options in VB.NET
Enumerated data types
enums
Ad

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

PPT
Arrays
PDF
Vb6 ch.8-3 cci
PPTX
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
PDF
VB PPT by ADI PART3.pdf
PDF
VB PPT by ADI PART3.pdf
PPTX
Presentation on visual basic 6 (vb6)
PPT
05 control structures 2
PPTX
Sharbani bhattacharya VB Structures
PPTX
Loop structures chpt_6
DOCX
VBScript Functions procedures and arrays.docx
PDF
Conditional Statements & Loops
PPT
AVB201.2 Microsoft Access VBA Module 2
PDF
Vb.net ii
PPTX
VB(unit1).pptx
PPT
Ms vb
PPT
Visual basic 6.0
Arrays
Vb6 ch.8-3 cci
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VB PPT by ADI PART3.pdf
VB PPT by ADI PART3.pdf
Presentation on visual basic 6 (vb6)
05 control structures 2
Sharbani bhattacharya VB Structures
Loop structures chpt_6
VBScript Functions procedures and arrays.docx
Conditional Statements & Loops
AVB201.2 Microsoft Access VBA Module 2
Vb.net ii
VB(unit1).pptx
Ms vb
Visual basic 6.0
Ad

More from robertbenard (20)

PPTX
Sample
PPTX
PPTX
Accessing data within VB Applications
PPTX
Advanced VB: Object Oriented Programming - Controls
PPTX
Advanced VB: Object Oriented Programming - DLLs
PPTX
Advanced VB: Review of the basics
PPTX
Copyright Basics
PDF
Cascading Style Sheets in Dreamweaver
PPTX
Performance Assessment Task
PPT
WIDS Jeopardy
PPT
Wids Model
PPT
Lesson 2
PPT
Lists, formatting, and images
PPT
Lesson 7
PPT
Lesson 6
PPT
Lesson 5
PPT
Lesson 4
PPT
Lesson 3
PPT
Lesson 1
PPT
Lesson 1
Sample
Accessing data within VB Applications
Advanced VB: Object Oriented Programming - Controls
Advanced VB: Object Oriented Programming - DLLs
Advanced VB: Review of the basics
Copyright Basics
Cascading Style Sheets in Dreamweaver
Performance Assessment Task
WIDS Jeopardy
Wids Model
Lesson 2
Lists, formatting, and images
Lesson 7
Lesson 6
Lesson 5
Lesson 4
Lesson 3
Lesson 1
Lesson 1

Recently uploaded (20)

PDF
Sports Quiz easy sports quiz sports quiz
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Lesson notes of climatology university.
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
RMMM.pdf make it easy to upload and study
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Sports Quiz easy sports quiz sports quiz
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
01-Introduction-to-Information-Management.pdf
Lesson notes of climatology university.
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Institutional Correction lecture only . . .
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Supply Chain Operations Speaking Notes -ICLT Program
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Computing-Curriculum for Schools in Ghana
Microbial diseases, their pathogenesis and prophylaxis
Abdominal Access Techniques with Prof. Dr. R K Mishra
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
O7-L3 Supply Chain Operations - ICLT Program
RMMM.pdf make it easy to upload and study
Anesthesia in Laparoscopic Surgery in India
PPH.pptx obstetrics and gynecology in nursing
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF

Advanced VB: Review of the basics

  • 1. Review of the BasicsAdvanced Visual Basic
  • 2. OverviewYou 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. VariablesYou 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. VariablesResearch Question: What is the difference between a variable and a constant?
  • 5. ArraysAn 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. ArraysResearch Question: How many elements are in this array?Dim strStudentNames(10) As String
  • 7. LoopsVisual 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 = 10Do 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.ControlsthisControl.BackColor= System.Drawing.Color.LightBlueNext thisControlEnd Sub
  • 12. LoopsResearch Question: What happens when a loop doesn’t end? Dim intValue as integer = 1 Do Until intValue = 2MessageBox.Show(“you have a problem!”) Loop
  • 13. DecisionsVisual 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 valuesExample: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. DecisionsResearch Question: What is the most efficient way to determine if someone can vote?Consider: Age = 17Age = 18Age = 19
  • 17. Additional InformationFor additional information about these topics, please review your text and the links provided in Blackboard.