Presentation is loading. Please wait.

Presentation is loading. Please wait.

Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.

Similar presentations


Presentation on theme: "Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San."— Presentation transcript:

1 Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San Diego

2 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Ch. 8: Arrays  Set up and use a control array  Selection construct, Case/End Case  Array of variables  Use For Each/Next loop structure  Direct vs. indirect table access  List ItemData property  Multidimensional arrays

3 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Control arrays  Control array is a group of like-named controls of same type  Advantage is that controls in array share a single click event  Disadvantage: loss of mnemonic naming  Create control array by assigning each control, in turn, by same name

4 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Case structure  Case is another selection structure similar to If/Then/Elseif structure  You use case when a variable or expression can be one of several values and If statement would be cumbersome  Any Case statement could be coded as a series of nested If statements.

5 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Case (continued)  Elements used for constant list are like these: –Case 2, 5, 9 –Case 25 to 50 –Case Is < 14  Case expression can be text as well as numeric  Case Else is a default case activated when none of the other cases apply

6 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Single Dimensional Arrays  Variable array can contain a list of values  Individual values are called elements  Elements are just like any other variable  You refer to an element using its subscript  Arrays are sometimes called tables  Each array element is of same type

7 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill For Each/Next Statements  For Each loops let you reference all elements w/o knowing how many there are  Form: For Each variant-var In arrayname statement(s) Next  Also a convenient way to set all controls on a form "", 0, or some other value

8 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill User-Defined Data Types  You can define your own data types  These user-defined types are sometimes called records because they encompass several data types bundled into one type  You define the type and then assign the type to variables—two steps

9 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Using Arrays to Tally Stats.  Arrays are often used to accumulate sums for discrete categories represented by each element of an array  Each element is a separate accumulator  How do you ensure that someone doesn't attempt to fill array element 12 when there are only 10 elements?

10 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Table Lookup  When groups are not numbered in sequence, then you can use table lookup techniques  Table lookup requires you to store an ID along with the value being tallied—at least two different elements  You must search the table for the ID and then update the associated tally.

11 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Using List Boxes with Arrays  It is handier to use a list box to lookup a value and then use that to access an array element.  List boxes simplify identifying groups because they constrain IDs to the list  ItemData property of a list associates a number with a list box element--even when the list is sorted

12 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Multidimensional Arrays  You can use 2 subscripts with an array Dim X(1 to 10, 5 to 15) As Integer or Dim X(2,7) As String  First subscript is row; second is column  Printing 2X array requires nested For loops  Application: Shipping rates based on: –weight –distance

13 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Hands-on Programming


Download ppt "Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San."

Similar presentations


Ads by Google