Presentation is loading. Please wait.

Presentation is loading. Please wait.

Don’t Leave Home Without them

Similar presentations


Presentation on theme: "Don’t Leave Home Without them"— Presentation transcript:

1 Don’t Leave Home Without them
ARRAYS Don’t Leave Home Without them

2 Problem: I NEED to hold many values at the same time.
SITUATION: But I can only hold a single value at a time with a variable. SOLUTION: USE an ARRAY !!!!!!

3 An array is a set of elements that are all the same data type.
What is an ARRAY?

4 I need some information from you first.
How do I create an array? I need some information from you first.

5 What type of data do you need to store?
I need some Information from you first. Ok…so string!! And how many? Uummm, names ? Idk… 5…. I guess.

6 Dim strname(4) as String Notice the number isn’t 5.
This is how you declare a STRING array of 5. Dim strname(4) as String Notice the number isn’t 5. But it is the spot (or index) of the last element. strname

7 Dim strname(4) as String
And, of course, the datatype depends on your data. Now Class try you hand at these array declarations….. I’ll hand out the worksheets!

8 idk….. Ask the class? What names do you want to store in the array?
Dim strname(4) as String idk….. Ask the class?

9 But how do I store data in arrays using Visual Basic?
Dim strname(4) as String There are two ways to do that…… But how do I store data in arrays using Visual Basic?

10 First way is with an initializer list.
Dim strname() as String= {“Ann”, “Bob”, “Carrie”, “David”, “Elaine”} First way is with an initializer list. Oh ok.

11 Second way is using a For…Next loop. I love for loops!!!!
Dim strname(4) as String Second way is using a For…Next loop. I love for loops!!!!

12 Oh good. We are going to need that in the for loop.
Dim strname(4) as String You need to know that arrays do have a property called length, which returns the number of elements in the array. Oh good. We are going to need that in the for loop.

13 Dim strname(4) as String Dim intloop as Integer
For intloop = 0 to strname.length-1 strname(intloop) =InputBox(“Enter a name:”) Next intloop The index or subscript of the array is the loop variable! I know how to use for loops!

14 I did it! I’m so smart! I feel transformed! Wow! I’m proud of you!
Now CLASS make me proud! Do the Student Names Application on page 9-2 to 9-3 I did it! I’m so smart! I feel transformed!

15 How big is the array: Dim intstudents(765) as integer? 766
2. Why don’t you use a size when loading with an initializer list? Computer counts the number of items in your list and sizes the array 3. What loop structure goes hand-in-hand with arrays? For Loops 4. What is the property name that gives you the size of the array? length 5. What is the first index of every array? Because I have a collection of elements all of the same datatype. 6. Why do I want to use arrays?


Download ppt "Don’t Leave Home Without them"

Similar presentations


Ads by Google