Well start in a moment - PowerPoint PPT Presentation

1 / 75
About This Presentation
Title:

Well start in a moment

Description:

Share an interesting story or fact about yourself with the class. What ... Do not enter a login name or password when prompted to do so, ... Light-hearted ... – PowerPoint PPT presentation

Number of Views:83
Avg rating:3.0/5.0
Slides: 76
Provided by: larrylan
Category:

less

Transcript and Presenter's Notes

Title: Well start in a moment


1
Well start in a moment
  • Get Ready to Answer These
  • What is your name?
  • Tell us about your background.
  • Share an interesting story or fact about yourself
    with the class.
  • What are your hobbies?
  • What do you hope to get from this class?
  • Turn on your computer
  • Do not enter a login name or password when
    prompted to do so, simply hit Enter or click the
    OK button.
  • Start Internet Explorer
  • Start Menu
  • Internet -gt Internet Explorer

2
Visual Basic Programming II Orientation and
Lecture 1
MIS 233 Instructor Larry Langellier
3
An Important Thing to Know!
  • The Home Page for the course
  • http//Online.MoraineValley.edu/WebSupported/MIS23
    3-Langellier

4
The Syllabus
  • Click the Syllabus link at the top of the Home
    Page
  • Details on
  • The Instructor
  • Textbooks
  • Grading
  • Prerequisites
  • Policies and
  • Procedures

5
Syllabus Details
  • Office Location
  • Office Hours
  • Phone Numbers
  • Email Address
  • Prerequisites
  • Textbooks
  • Schedule
  • Policies
  • Withdrawal
  • Refunds
  • Attendance
  • Preparation
  • Cheating/Plagiarism
  • Working Together
  • Cell phones silenced

6
Syllabus Details - Grading
  • Distribution
  • Homework 25
  • Mini-Projects 25
  • WebBoard 10
  • Research Presentation 5
  • Midterm Project 15
  • Final Project 20
  • Late Homework is penalized 20
  • Homework more than 1 week late will not be
    accepted
  • Scale
  • A 93 100
  • B 85 92
  • C 76 84
  • D 70 75
  • F Below 70

7
What will this course be like?
  • Multiple Learning Styles accommodated
  • Learn by Reading Learn by Listening
  • Learn by Doing Lectures
  • Homework problems Learn by Mistakes
  • Just Do It! Exercises Fail early, Fail often
  • Learn by Questioning Learn by Example
  • Ask questions on the WebBoard HW and JDI
    solutions
  • Learn by Teaching Examples in the textbook
  • Answer questions on the WebBoard
  • Learn by Group Interaction
  • Group Do It Together Exercises

8
How to Use the WebBoard
  • 10 of your grade will be based on participating
    on the class WebBoard
  • You must
  • Post at least three relevant questions, comments,
    observations, summaries, pseudocode samples,
    discussions or answers to the current questions
    of others
  • Only serious contributions count!
  • Light-hearted submissions are welcome
  • All postings are subject to standards of
    appropriate conduct
  • Logon
  • http//Online.MoraineValley.edu/WebSupported/MIS23
    3-Langellier
  • Click on WebBoard
  • Click the New User button
  • Fill out the User Profile use your real name
    and email address!

9
How to Use the WebBoard
  • How to Post
  • For new discussions
  • Select a Conference
  • Select Post (at the top)
  • Enter a topic
  • Enter your message
  • Click the Post button
  • How to Reply
  • To answer some elses post that you are reading
  • Select the reply option above the message you
    are reading
  • Type in your follow-up message
  • Click the Post button
  • Chat

10
WebBoard Usage
  • Do
  • Ask Questions
  • Post Pseudocode (youll learn what that is)
  • Answer Questions
  • Discuss class topics
  • Share design ideas (even on homework assignments)
  • Clarify poorly worded homework questions (it
    happens)
  • Discuss solutions to past homework exercises
  • Dont
  • Post the code for your homework solutions before
    the due date
  • Dont share your code with anyone, in any way,
    prior to the due date
  • Act like a poor citizen in any way
  • The rules of the college still apply on the Web

11
Get To Know Your Instructor
  • Lets practice using the WebBoard
  • Everyone must ask me one question.
  • Go to the Your First Post conference
  • Post your Question to the WebBoard
  • The topic should contain a summary of your
    question
  • The body of the message could contain a more
    detailed version of your question
  • Youll be able to read my replies tomorrow
  • Logoff when youre done

12
The Course Schedule
  • Select Master Schedule on the Home Page menu
  • A summary of each week
  • Reading Assignments
  • Topics covered
  • Homework Deadlines
  • A good place to see
  • whats going on at
  • a glance

13
Topics Covered In This Course
  • Loops and Decisions
  • Event-Driven Programming
  • Debugging
  • Lists and Arrays
  • Numeric and String Functions
  • File Processing
  • Error Trapping
  • Classes and Objects
  • Modular Design
  • Three-Tier Architecture
  • Database Access

14
Topics Not Covered In This Course
  • Internet Programming
  • VB.NET (well, there will be some)
  • COM Components
  • Help Systems
  • n-Tier Architecture
  • Creating Installations
  • Advanced Object Modeling and Design
  • Database Design

15
Homework
  • Click the Homework menu item on the Home Page
  • All assignments and due dates for the semester
    are listed

16
Homework
  • Via Email
  • Attach .vbp, .vbw, .bas, .cls, .frm, and .frx
    solution files (only) for the homework
    assignments
  • If the assignment includes written exercises,
    type the written solutions in Microsoft Word or
    Notepad and submit the .doc or .txt file
  • The Subject Line of your email message must
    reflect what class (MIS233), which homework, and
    your name.
  • e.g. MIS233 HW1 Joe Blow
  • Attach all solutions for one week to a single
    e-mail
  • No More
  • No Less
  • If you are going to be late, wait to submit until
    youre done
  • Microsoft Word will be used to grade homework
  • http//download.microsoft.com/download/word2000/vi
    ewer/1/win98/EN-US/Wd97vw32.exe

17
Homework
  • Dues Dates
  • By the beginning of class on the deadline date
    listed for the assignment
  • Late Penalty
  • 20 for anything one second late to one week late
  • 100 for everything more than one week late
  • Only one submission is accepted
  • You will have to decide whether to turn in
    partial solutions or take the penalty and turn in
    late solutions I wont accept two submissions
  • Solutions
  • Will be returned with your graded homework

18
Projects and Presentations
  • Mini-Projects
  • The Mini-Projects will require you to apply and
    combine numerous programming concepts youve
    learned to that point to a larger problem that I
    provide specifications for.
  • Research Presentation
  • The field of computer programming changes
    rapidly. To keep from falling behind you need to
    stay current with technology changes. This
    project will require you select an emerging
    technology related to Visual Basic, research it,
    and present an oral summary of your findings to
    the class. I will provide a list of possible
    topics, but if youll also have the opportunity
    to select your own topic with my permission.
  • Final Project
  • The Final Project will be the culmination of all
    the hard work you do this semester. You will
    select your own project, design a solution,
    implement and test the software, create a user
    guide, and demonstrate your project to the class
    during the last class period.

19
Time to answer my questions
  • Post a Reply to the WebBoard
  • Select the Tell Us About Yourself Conference
  • Read the About the Instructor posting I made,
    telling you about myself
  • Reply (dont Post like we did before)
  • Answer some simple questions about yourself
  • What is your name?
  • Tell us about your background.
  • Share an interesting story or fact about yourself
    with the class.
  • What are your hobbies?
  • What do you hope to get from this class?
  • Feel free to tell us more

20
Contacting the Instructor
  • WebBoard
  • Post questions regarding course content,
    policies, etc.
  • Office Hours (listed in the syllabus)
  • Drop by if youd like to discuss things in person
  • By Appointment
  • If my office hours are impossible for you to
    attend, feel free to email or phone to see if we
    can arrange a time
  • Telephone
  • (708) 974-5339
  • Im not in the office very often - leave a
    message if I dont answer
  • If one of my office mates answers, ask them to
    transfer you to voice mail
  • E-mail
  • Reserved for items of a personal nature that
    cant be posted to the WebBoard (i.e. illnesses,
    etc.)

21
Other Materials
  • Instructors Website
  • http//Online.MoraineValley.edu/Websupported/Lange
    llier/
  • Weekly Lecture Notes
  • PowerPoint summary of the presented materials
  • Just Do It! Hands-on exercises with solutions
  • Homework Solutions
  • Returned with your graded homework
  • Resources
  • Index

22
Good Luck!!!

23
Review
  • Selection Structures
  • IfThenElse
  • Select Case
  • Relational Operators
  • , gt, lt, ltgt, gt, lt
  • Logical Operators
  • And, Or, Xor, Not
  • Input Box and Message Box
  • The Format() Function
  • Formatting Numbers, Dates and Time
  • Random Number Generation

24
More MIS130 Review
  • Scope Variables and Procedures
  • Procedure-level
  • Module-level
  • Global-level
  • Static
  • Working with Multiple Forms in an Application
  • User-Defined Data Types
  • Loops
  • For
  • Do Until
  • Do While
  • While
  • Control Arrays
  • Timer Control

25
Control Structures
  • Computing problems can be solved by executing a
    series of actions in a specific order - this is
    called an algorithm
  • Control structures determine the order statements
    are executed. All algorithms can be written
    using three basic control structures
  • Sequential
  • Selection
  • Repetition
  • Pseudocode is useful for developing algorithms
    without writing code. A programmer can think
    out their solution in English prior to writing
    Visual Basic.

26
IfThenElse
  • Selection structures enable solutions that will
    (or will not) execute a statement (or sequence of
    statements) based on the value of a condition
  • In Pseudocode
  • If the child is taller than 2 6
  • Display You may ride the carnival rides
  • Notice the indentation for the conditionalized
    action
  • Visual Basic provides the IfThen and
    IfThenElse statements to allow you to select
    whether to execute an action or sequence of
    actions

27
IfThenElse Syntax
  • Form 1 (on one line)
  • If test-condition Then statement Else statement
  • Form 2 - Example 8.1
  • If test-condition Then
  • statement block
  • Else
  • statement block2
  • End If
  • Form 3 - Example 8.2
  • If test-condition Then
  • statement block
  • ElseIf test-condition2
  • statement block2
  • Else
  • statement block-n
  • End If

28
IfThenElse Example
  • If grade gt 93 Then
  • lblStudentGrade.Caption "A"
  • Else
  • If grade gt 85 Then
  • lblStudentGrade.Caption "B"
  • Else
  • If grade gt 76 Then
  • lblStudentGrade.Caption "C"
  • Else
  • If grade gt 70 Then
  • lblStudentGrade.Caption "D"
  • Else
  • lblStudentGrade.Caption "F"
  • End If
  • End If
  • End If
  • End If

29
IfThenElseIf Example
  • If grade gt 93 Then
  • lblStudentGrade.Caption "A"
  • ElseIf grade gt 85 Then
  • lblStudentGrade.Caption "B"
  • ElseIf grade gt 76 Then
  • lblStudentGrade.Caption "C"
  • ElseIf grade gt 70 Then
  • lblStudentGrade.Caption "D"
  • Else
  • lblStudentGrade.Caption "F"
  • End If

30
Test Conditions and Relational Operators
  • A Test Condition is basically a question you ask
    that has a True or False (or yes/no) answer
  • Is it raining?
  • Is myName Larry?
  • The answer may vary depending on
  • when you ask
  • what the variable values are when you ask
  • Relational Operators allow you to compare two
    values. Visual Basic includes
  • Equality ltgt Inequality
  • gt Greater Than gt Greater Than or Equal To
  • lt Less Than lt Less Than or Equal To

31
Logical Operators
  • Relational Test Conditions can be built into
    larger test expressions using Logical Operators
  • For Example
  • If it is raining and you have your umbrella
  • Visual Basic provides 3 primary Logical
    Operators
  • And True only if both operands are true
  • Or True if one or both operands are true
  • Not True only if the single operand is false

32
Operator Precedence
  • Arithmetic, Relational and Logical operators are
    performed in a specific order within a single
    expression. This order is determined by
    precedence rules
  • Exponentiation HIGHEST
  • - Negation (unary operation)
  • , / Multiplication and Division
  • \ Integer Division
  • Mod Modulo Arithmetic
  • , - Addition and Subtraction
  • String Concatenation
  • , ltgt, gt, gt, lt, lt Logical Operators
  • Not Logical Negation (unary operation)
  • And Conjunctive
  • Or Inclusive Or LOWEST

33
Using IfThen Logic to Manipulate Objects
  • Examples
  • A button that constantly shifts between two
    messages
  • Example 8.3
  • An enhancement to the prior example that displays
    a message box every sixth time the button is
    clicked
  • Example 8.5
  • Display different messages depending on where the
    slider is in a scroll bar
  • Example 8.6

34
Sample Problem
  • Provide two text boxes for the user to enter
    numbers
  • and a Test Them button. After the user enters
  • numbers a clicks the button, display a message
  • declaring which number was the largest. If the
    numbers
  • are both equal, display a message to that effect
    instead.

35
Interface Prototype
36
Sample Pseudocode
  • If the first number is larger
  • Display a message showing the value of the 1st
  • Else if both numbers are equal
  • Display a message saying both are equal
  • Else
  • Display a message showing the value of the 2nd

37
Sample Solution
  • Private Sub cmdTest_Click()
  • If CInt(txtNum1.Text) gt CInt(txtNum2.Text)
    Then
  • lblMessage.Caption txtNum1.Text " is
    the largest."
  • ElseIf CInt(txtNum1.Text)
    CInt(txtNum2.Text) Then
  • lblMessage.Caption "Both numbers are
    equal."
  • Else
  • lblMessage.Caption txtNum2.Text " is
    the largest."
  • End If
  • End Sub

38
Select Case
  • The IfThenElseIf selection statement allows
    choosing between several alternative courses of
    action
  • Visual Basic also provides another statement for
    choosing among alternatives - the Select Case
  • Syntax
  • Select Case testvariable
  • Case expressionlist1
  • actionlist1
  • Case expressionlist2
  • actionlist2
  • Case Else
  • actionlist-n
  • End Select

39
Select Case (cont.)
  • Comma Delimited Multiple expressionlist
  • Case 0, 5, 8, 11, 13
  • Range Delimited Expression
  • Case 21 To 27
  • Case Is gt 20
  • Examples
  • Redo the scroll bar ElseIf example
  • Example 8.7
  • Respond to a job applicants salary request
  • Example 8.8
  • Identifying World Capitals
  • Example 8.9

40
The Input Box
  • The InputBox() function displays a dialog box
    that waits for the user to input a piece of
    information.
  • Syntax
  • InputBox(prompt, title, default, xpos,
    ypos)
  • where
  • prompt is a message displayed in the dialog box
  • title is displayed in the input box title bar
  • default is the response if no other input is
    provided
  • xpos is the horizontal distance from the left of
    the screen and
  • ypos is the vertical distance from the top of
    the screen
  • InputBox returns a string containing the answer
    the user input
  • Example - Using the Input Box for Data Entry (9.1)

41
The Message Box
  • The MessageBox() function is used to display
    information to the user
  • Syntax
  • MsgBox(prompt, buttons, title)
  • where
  • prompt is a message displayed in the dialog box
  • buttons specify the number and type of buttons
    to display and
  • title is displayed in the input box title bar
  • Return Values
  • vbOK, vbCancel, vbAbort, vbRetry, vbIgnore,
    vbYes, vbNo
  • Example - Exploring different MsgBox types (9.2)

42
Do It Together!
  • Write a program to determine a persons grade on
    an
  • exam. Use an InputBox to get their exam score
    and a
  • MsgBox to display their grade based on that
    score. The
  • exam grade should be calculated using a Select
    Case
  • statement where the grade scale is as follows
  • 93-100 A
  • 85-92 B
  • 77-84 C
  • 70-76 D
  • Below 70 F

43
Interface Prototypes
44
Sample Solution
  • Private Sub cmdGrade_Click()
  • Dim nGrade As Integer
  • Dim sMessage As String
  • nGrade InputBox("Enter your exam score",
    "Exam Grader", 0)
  • Select Case nGrade
  • Case Is gt 93
  • sMessage "You received an A on the
    Exam."
  • Case Is gt 85
  • sMessage "You received a B on the
    Exam."
  • Case Is gt 77
  • sMessage "You received a C on the
    Exam."
  • Case Is gt 70
  • sMessage "You received a D on the
    Exam."
  • Case Else
  • sMessage "You received an F on the
    Exam."
  • End Select
  • MsgBox sMessage, vbExclamation, "Exam Grade"
  • End Sub

45
The Format() Function
  • The Format() function allows you to display
    values in traditional ways users have come to
    expect to see them
  • Various Date and Time formats
  • Currency
  • Percentages
  • Comma separated thousands
  • Syntax
  • Format(expression, format)
  • where
  • expression is an valid expression to be
    formatted and
  • format is a valid named or user-defined format
    expression
  • Example - Entering and Displaying Numeric Data
    (9.4)

46
Random Number Generation
  • Randomize
  • Should be called once in your program
  • Establishes a different starting point for the
    random sequence
  • Rnd()
  • Generates a decimal random number between 0 and 1

47
Random Numbers (cont.)
  • Scaling
  • Obviously, you will frequently want random
    numbers outside this range
  • To scale to the range of values you want, do the
    following
  • Multiply the random number by how many values are
    in the range you desire (I.e. There are 101
    values if you want the range 0 - 100)
  • Extract the integer portion of this calculation
    using the Int function
  • Add the value of the starting position
  • Example - The Range 10 To 90
  • 10 Int(81 Rnd)

48
Scope
  • Scope is comprised of two parts
  • Where something can be accessed or called from
  • aka visibility
  • How long an item is in existence
  • aka lifetime
  • Both variables and procedures have scope
  • In Visual Basic, scope is determined by
  • where a variable or procedure is declared
  • certain keywords such as Private, Public, Static

49
Variable Scopes
  • Procedure-level Variables
  • Visibility only available in the procedure where
    declared
  • Lifetime comes into existence when the procedure
    is called and ceases to exist when the procedure
    is exited
  • Module-level Variables
  • Visibility anywhere inside the module where
    declared
  • Lifetime the whole time the containing module is
    loaded
  • Global-level Variables
  • Visibility anywhere, everywhere
  • Lifetime the whole time the application is
    running
  • Static Variables (procedure-level only)
  • Visibility only available in the procedure where
    declared
  • Lifetime the whole time the containing module is
    loaded

50
Declaring Variables
  • Typical variable declaration statement
  • Dim variableName As type
  • Always declare your variables before using, even
    though Visual Basic doesnt require it
  • Use Option Explicit at the top of all modules
    or
  • Tools -gt Options -gt Editor Tab Require Variable
    Declaration

51
Procedure-level Variables
  • Declared inside a Procedure or Function
    declaration
  • Place all variable declarations for a procedure
    at the top
  • Enhances readability
  • Uses keyword Dim
  • Dim variableName As type
  • Example
  • Exercise 10.1

52
Module-level Variables
  • Defined in the General Declarations section of
    any Form (.frm), Code (.bas) or Class (.cls)
    module.
  • Accessible by any procedure written for that
    module
  • Use either the Dim or Private keyword
  • Private variableName As type
  • Dim variableName As type
  • Keep in mind these variables are only in
    existence while the module is loaded.
  • Example
  • Exercise 10.2

53
Global-level Variables
  • Declared in the General Declarations section of a
    Code (.bas) module only
  • Visible everywhere from within the application
    and exists the whole time the application is
    running
  • Uses the Public keyword
  • Public variableName As type
  • Example
  • Exercise 10.3

54
Static Variables
  • Static variables can only be declared in
    procedures or functions
  • Visible only within the procedure where it was
    declared, but it stays in existence as long as
    the module is loaded
  • Combines aspects of procedure-level and
    module-level variables
  • Uses the Static keyword
  • Static variableName As type
  • Example
  • A classic use of a static variable is as a
    counter
  • Public Sub First()
  • Static Num As Integer
  • Num Num 1
  • End Sub

55
Overriding Scope Declarations
  • Procedure-level scope takes priority over higher
    level scope definitions (like module or global)
  • This means the variable declared within a
    procedure will be the one used, even if another
    variable of the same name is declared at a higher
    level
  • Example
  • Exercise 10.4

56
Procedure Scope
  • Procedures and Functions have scope also
  • You can control how limited or expansive the
    access to a procedure is by using
  • Private to limit access to only the module where
    declared -or-
  • Public to provide unlimited global access (as
    long as the module is loaded)
  • Syntax
  • Public Sub subName()
  • 'Statements go in here
  • End Sub
  • Public Funtion subName() As dataType
  • 'Statements go in here
  • End Function
  • Examples
  • Exercises 10.5 and 10.6

57
Multi-Form Applications
  • Visual Basic applications can have more than one
    form associated with them
  • You can control the visibility and loading of
    forms through a variety of statements and methods
  • Load
  • Visual Basic only loads the startup form when an
    application starts, you can load more with the
    Load statement
  • Load frmName
  • Show
  • Make a form visible
  • frmName.Show style
  • Hide
  • Make a form invisible
  • frmName.Hide style
  • Unload
  • Remove a form from memory
  • Unload frmName

58
Multi-Form Applications (cont.)
  • Example using more than one form
  • Exercise 10.9
  • You can use a Main() procedure in the standard
    code module to start an application
  • Example starting with code rather than a form
  • Exercise 10.10
  • The benefits of starting from code include
  • having a place to do error-checking before an
    application starts
  • being able to have different entry points to an
    application, depending on chosen parameters
  • allowing initialization to occur prior to loading
    a form

59
An Example
  • Lets create four different forms (named
    frmColor1,
  • frmColor2, frmColor3, and frmColor4) and a
    standard
  • code module. Each form should display a
    different
  • color as its background color but lets do
    that a run-time, not
  • design-time.
  • Use a standard code module to declare and write a
    Main()
  • procedure. This Main() should call four
    procedures color1,
  • color2, color3 and color4. Each of these
    procedures should load
  • the corresponding form, show the form, change the
    caption of the
  • form and change the form background color to a
    different color
  • than each of the rest.

60
Sample Solution
  • In the .bas file
  • Sub main()
  • Call color1
  • Call color2
  • Call color3
  • Call color4
  • End Sub
  • Sub color1()
  • Load frmColor1
  • frmColor1.Show
  • frmColor1.Caption "Red"
  • frmColor1.BackColor vbRed
  • End Sub
  • Repeat for other three forms

61
User-Defined Data Types
  • Visual Basic includes a capability that allows
    the programmer to declare new data types that are
    created from the primitive data types these are
    called User-Defined Types
  • Other languages call this concept
  • A Structure (C)
  • A Record (Pascal or databases)
  • UDTs consist of one or more elements, and the
    elements can be different types
  • The purpose of a UDT is to combine many
    different, though related, pieces of data
    together into a single construct
  • UDTs are similar to the Classes well learn later

62
User-Defined Data Types (cont.)
  • Syntax
  • Private Public Type typeName
  • elementName1 As dataType1
  • elementName2 As dataType2
  • End Type
  • UDTs must be declared at the module-level of a
    code (.bas) module
  • Declaration of the UDT doesnt reserve any memory
    to store anything you must declare a variable
    of that type get storage
  • Access to the individual elements is through the
    dot operator like the properties of controls
    and forms
  • Example Exercise 10.11

63
Do It Together!
  • Write a program that defines a Student
    user-defined
  • data type. Include a name, social security
    number, and
  • grade point average as elements in the data type
  • definition.
  • Create a form with a single button. When that
    button is
  • clicked pop up three separate Input Boxes, one
    for
  • each attribute of the UDT. Store the entries in
    the
  • attributes of a procedure-level variable that is
    of the
  • user-defined type. Finally, display the values
    from the
  • UDT variable attributes on the Form.

64
Sample Solution
  • In the .bas file
  • Type Student
  • Name As String
  • SSN As String
  • GPA As Double
  • End Type
  • In the .frm file
  • Private Sub cmdDisplay_Click()
  • Dim aStudent As Student
  • aStudent.Name InputBox(Enter the students
    Name)
  • aStudent.SSN InputBox(Enter the students
    SSN)
  • aStudent.GPA InputBox(Enter the students
    GPA)
  • Print aStudent.Name
  • Print aStudent.SSN

65
Loops
  • Loops are used to execute a statement (or group
    of statements) repeated in a controlled fashion
  • Loops can execute a fixed number of times or
    until a test condition becomes true or false
  • Visual Basic provides several different types of
    loops
  • For-Next
  • Do (4 varieties)
  • While
  • These various types of loops all control repeated
    execution, but each is specially suited for
    different situations

66
For-Next Loop
  • For-Next loops control executing a block of
    statements a fixed number of cycles
  • Syntax
  • For counter start To end Step increment
  • statements
  • Next counter
  • The counter is an integer variable which contains
    a value between start and end depending on the
    current iteration
  • The default is to increment count by 1 each time
    around the loop you can use Step to control how
    much to increment by
  • Example Exercise 11.1

67
Control Arrays
  • A control array is a group of controls all of
    which have the same name
  • How do you tell one from another if they each
    have the same name?
  • Their Index
  • How do you create a control array?
  • Copy an existing control that youve already
    named and Paste it
  • Give a new control the same name as one that
    already exists
  • Why would you want several controls to have the
    same name?
  • This allows you to use a loop to iterate through
    several related controls
  • Example Exercise 11.2

68
Nested For-Next Loops
  • Loops can be nested inside other loops
  • With a nested loop, the innermost loop must
    finish executing before the outside loop is
    incremented to start the cycle over again
  • Example
  • Exercise 11.3

69
An Example
  • Modify Exercise 11.3 to display the following
    pattern
  • 10 8 6 4 2
  • 10 8 6 4
  • 10 8 6
  • 10 8
  • 10
  • Use the five list boxes from the example and also
    use
  • nested loops.

70
Sample Solution
  • In the .frm file
  • Private Sub cmdTryIt_Click()
  • Dim inner As Integer
  • Dim outer As Integer
  • Dim count As Integer
  • count 0
  • For outer 1 To 10 Step 2
  • For inner 10 To outer Step 2
  • lstNest(count).AddItem (inner)
  • count count 1
  • Next inner
  • count 0
  • Next outer
  • End Sub

71
Do Loops
  • Do loops execute while a condition is true or
    until a condition becomes true
  • Syntax
  • Do While Until condition
  • statements
  • Exit Do
  • more statements
  • Loop
  • Do
  • statements
  • Exit Do
  • more statements
  • Loop While Until condition

72
Do Loops (cont.)
  • Do-While Loop
  • performs a test at the top, testing for a
    positive condition
  • Do-Loop While
  • performs a test at the bottom, tests for a
    positive condition, always executes at least once
  • Do-Until Loop
  • performs a test at the top, testing for a
    negative condition
  • Do-Loop Until
  • performs a test at the bottom, tests for a
    negative condition, always executes at least once
  • Examples
  • Do-Loop Until Exercise 11.6
  • Do-Loop While Exercise 11.7
  • Nested Do Loops Exercise 11.9

73
While Loops
  • The While loop is similar to the Do-While
  • Syntax
  • While condition
  • statements
  • Wend
  • Just a slightly simpler-to-read version

74
The Timer Control
  • Visual Basic provides a built-in control that
    cycles repetitively the Timer control
  • The Timer control can sometimes be used instead
    of a loop especially if you want to control how
    long code executes based on time rather than
    repetitions
  • The Interval Property
  • Sets the number of milliseconds between calls to
    the Timer
  • Setting this to zero disables the Timer
  • The Enabled Property
  • Set to false to disable, or true to enable the
    Timer
  • Example
  • Exercise 11.10

75
Next Week
  • Read Chapters 8 to 11 to Review what we covered
    tonight
  • Read Chapters 12 and 13 to prepare for next Week
  • Class will begin with a presentation on how to
    use the LRC and the Internet to conduct research
  • This presentation be held in L207 from
    600-730pm
  • Feel free to meet there, or I will depart with
    anyone who would like to walk over from the
    classroom at 550pm.
  • We will return to the classroom after the
    presentation for lecture
  • Homework 1 is due next week prior to the
    beginning of class
  • Complete Chapter 1 (Rock, Paper, Scissors) in the
    Programming Games with Microsoft Visual Basic 6.0
    book.
  • Do the following end of chapter Skill-Building
    Exercises in your Eliason and Malarkey textbook
  • Chapter 10 - Ex. 5 and Ex. 8
  • Chapter 11 - Ex. 6
  • Mini-Project 1 is due next week prior to the
    beginning of class
  • E-mail the .vbp, .vbw, .frm, and .frx solution
    files to me
Write a Comment
User Comments (0)
About PowerShow.com