11
ARRAYS AND LISTBOXES LESSON Computer Programming I Module 13.2.1

Computer Programming I Module 13.2.1. This lesson illustrates how to code for arrays used to store data and how to display your data in listboxes

Embed Size (px)

Citation preview

Page 1: Computer Programming I Module 13.2.1. This lesson illustrates how to code for arrays used to store data and how to display your data in listboxes

ARRAYS AND LISTBOXES

LESSONComputer Programming I

Module 13.2.1

Page 2: Computer Programming I Module 13.2.1. This lesson illustrates how to code for arrays used to store data and how to display your data in listboxes

This lesson illustrates how to code for arrays used to store data and

how to display your data in listboxes.

Page 3: Computer Programming I Module 13.2.1. This lesson illustrates how to code for arrays used to store data and how to display your data in listboxes

CODE FOR ROLLING THE DICE?Often, arrays are used to store data. 

Please review the following code:

This program calculates the number of times the roll of a die generates a particular value.  Out of 10,000 rolls, one die will have roughly equal outcomes for each number of 1 to 6.

Page 4: Computer Programming I Module 13.2.1. This lesson illustrates how to code for arrays used to store data and how to display your data in listboxes

HOW TO KEEP UP WITH NUMBER OF TIMES A NUMBER IS ROLLED?

The code statements keep track of the frequency of times each number is

rolled by the following code:

Page 5: Computer Programming I Module 13.2.1. This lesson illustrates how to code for arrays used to store data and how to display your data in listboxes

HOW TO DISPLAY THE NUMBER OF ROLLS?

Thus, each time the dice are rolled, the element in each index is increased by one. The following code displays the number of times each outcome is rolled:

Page 6: Computer Programming I Module 13.2.1. This lesson illustrates how to code for arrays used to store data and how to display your data in listboxes

WHAT ARE THE ODDS AND PERCENTAGES?

Interestingly enough, no matter how many sets of times you roll 10,000 times, the percentages will always remain relatively constant. Why is this? Well, it has to do with odds and percentages.

  The code in the previous tab is just one

example of how arrays are used in programs to store data. What would happen to the percentages if a pair of dice were thrown instead of just one? In an upcoming assignment, you will get the opportunity to find out!

Page 7: Computer Programming I Module 13.2.1. This lesson illustrates how to code for arrays used to store data and how to display your data in listboxes

HOW ARE LIST BOXES USED?

List Boxes are used to display a list of items.  In the previous example with the dice, the form has a List Box which shows the following information:

Page 8: Computer Programming I Module 13.2.1. This lesson illustrates how to code for arrays used to store data and how to display your data in listboxes

LIST BOX PROPERTIES This will display the elements created. 

Some of the more useful properties of a List Box:

Page 9: Computer Programming I Module 13.2.1. This lesson illustrates how to code for arrays used to store data and how to display your data in listboxes

LIST BOX METHODS List Boxes also have methods that can

be used by the programmer to accomplish certain tasks.  Here are some of the more useful methods:

Page 10: Computer Programming I Module 13.2.1. This lesson illustrates how to code for arrays used to store data and how to display your data in listboxes

ARRAYS AND LIST BOX VIDEOClick the box below and view the following

video demonstration about Arrays and List Boxes.

Page 11: Computer Programming I Module 13.2.1. This lesson illustrates how to code for arrays used to store data and how to display your data in listboxes

WHAT’S NEXT?Now, it is time for you to demonstrate

your understanding of arrays and listboxes. Move on to 13.2.2 Arrays and

Listboxes Assignment.