Using Menus, Common Dialogs, Procedures, Functions, and Arrays - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Using Menus, Common Dialogs, Procedures, Functions, and Arrays

Description:

Using Menus, Common Dialogs, Procedures, Functions, and Arrays. 2 ... Unlike function procedures, sub procedures do not return values ... – PowerPoint PPT presentation

Number of Views:91
Avg rating:3.0/5.0
Slides: 24
Provided by: steve1703
Category:

less

Transcript and Presenter's Notes

Title: Using Menus, Common Dialogs, Procedures, Functions, and Arrays


1
Chapter 7
  • Using Menus, Common Dialogs, Procedures,
    Functions, and Arrays

2
Objectives
  • Understand menu bar, menus, shortcut menu,
  • Understand the StatusBar, the PictureBox
    controls,
  • Use one-dimensional and multidimensional arrays
    in code
  • Passing arguments to functions and procedures.

3
Know You Dog Quiz
  • The application displays a picture of a specific
    dog breed which the user must identify. User may
    navigate to the first, last, previous, or next
    question. To pass the quiz, the user must answer
    all questions correctly.

4
InterfaceDesign
5
Interface Design
  • A shortcut menu provides users with an easily
    accessible menu of commands, given the context of
    the application
  • A ContextMenu control is used to add the shortcut
    menu to the form
  • Use a common dialog box when a shortcut is used
  • A PictureBox control displays the image in
    different formats.
  • A StatusBar control anchors to the bottom of the
    form, displays status information.

6
Array
  • An Array holds many values. It provides a way to
    give several variables a common name and use an
    index to access each item.
  • Examples
  • Solution(1) 1 Solution(2) 4
  • QuestionChoice(1,1) English Springer Spaniel
  • QuestionChoice(1,2) Akita
  • QuestionChoice(1,3) Husky

7
Arrays
  • Allows programmers to represent many values with
    one variable name
  • Elements in the array are distinguished by their
    subscript
  • The lower-bound of a subscript is 0

For intNumber 0 To 11 dblTotal
dblMonth(intNumber) Next intNumber
8
The Dim Statement for Arrays
  • Dynamic dimension A variable or expression for
    upper-bound value
  • Dim intValues(intUpperBound) As Integer

9
Declaring Arrays
  • The program uses gshrAnswer array to track the
    users answers.
  • All values of array are initialized to -1
  • If the user licks the second RadioButton, the
    corresponding element receives a value of 1

10
Declaring Arrays
  • The solution to the quiz questions is stored in
    gshrSolution array, and compared to gshrAnswers
    array.
  • An element with a value of 0 indicates that the
    correct answer should be the answer displayed on
    the first RadioButton control.

11
Indexes
  • Elements in an array are referenced in code by
    their index

12
Multidimensional Arrays
  • VB. Net allows arrays to have up to 32
    dimensions.
  • Dim dblCost(2, 4) As Double

13
Multidimensional Arrays
Dim intTime() as Short _ 13, 30, 5, 17,
12, 45, _ 34, 26, 16, 26, 23, 35,
IntSum2 0 IntSum4 0 For intModel 0 TO 4
intSum2 intTime(intModel, 1) Next
intModel For intMachine 0 TO 5 intSum3
intTime(3, intMachine) Next intMachine
14
Declaring a Two-Dimensional Array
  • Quiz has seven questions, each of which has four
    answer choices and one image file
  • We use an array of 7 by 5.
  • Each question is represented by a row, with each
    answer choice represented by a column
  • The image file name is represented by the last
    column

15
Array Methods
  • You may use several array methods to retrieve
    information about an array

16
Sub Procedures
  • A sub procedure is a unit of code that executes
    when called from code in other procedures
  • Unlike function procedures, sub procedures do not
    return values
  • Like functions, sub procedures accept variables,
    constants and expressions as arguments

17
Function Procedures
  • Performs tasks and returns a value back to the
    code that called it
  • Similar to VB.NETs intrinsic functions

18
Returning a Value by a Function
  • You return a value from a function procedure to
    the line of code that called it by
  • Setting the function name to a value within the
    function before exiting.
  • Using the return statement

19
Function QuizResult()
  • The QuizResult() function returns True if the
    user answers all of the questions correctly.

20
Exit Menu Command and FontDialog Control
  • Click the Form1.vb tab in the main work area.
    Double-click the Exit command on the File menu of
    the Form1 form and type line 345 in the code
    window
  • Double-click the Font command on the Options
    menu, and type lines 349 through 355

21
Passing Arguments Between Procedures
  • Passing By Value method
  • ByVal keyword
  • Passes the value of the variable (default method)
  • CalculateTax((dblIncome),intTaxBracket)
  • Passing By Reference method
  • ByRef keyword
  • Passes the memory location of the variable
  • Allows you to modify the variable in procedure
  • Private Sub CalculateTax(ByRef dblValue As Double)

22
Coding a Sub Procedure
  • A sub procedure DisplayQuestion() displays a
    question to user and checks the radio buttons for
    the answer

23
Coding a Sub Procedure
  • The value of the radAnswer1.Checked property is
    compared with True.
Write a Comment
User Comments (0)
About PowerShow.com