20th October Lesson

Today we furthered yesterday’s lesson of arrays by discussing simpler ways to create programs by using arrays and providing examples.

Programmers prefer to count from 0 to 9, but we will count 1 to 10 as it is simpler.

Counting from 1 to 10 in play –
Dim IntAge(10)As Integer
Dim IntCounter As Integer
For IntCounter = 1 to 10
IntAge(counter) = InputBox(“Please enter number”)
Next

In the line “Dim IntAge(10) As Integer” the area where the 10 is – inside brackets – is where the programmer would enter the number of numbers they wish for the array to create.

When creating programs like this, only the programmer should be allowed to set number of items in the array to be created as if a user were to enter a high number such as one million the program would use a lot of space and eventually have the computer face problems with all it’s RAM gone.

“No_of_items = 100
Dim Name(No_of_items) as String
DimAge(No_of_items) As Integer”

The above code would create a simpler program because if any changes were needed all you would have to do is change one line of code.
_________________________

Array Output

Sometimes program code has to be written out for people who can not read a language such as Visual Basic. This is known as pseudocode. An example of how to do this is here –

Refining Step 3
3.1 For 100 Numbers (this would be seen as For Counter = 100 in VB_
3.2 Add current number to total
3.3 Next Number
3.4 Average = Sum total/100

Sometimes, these steps may not be clear enough and require a further explanation such as point 3.2, here we further it – Refining step 3.2
3.2.1 total = total + number

Refining Step 4

4.1 Display the sum of the number
4.2 Display the average
4.3 Display the values

Refining Step 4.3 –
4.3.1 For 100 numbers
4.3.2 Display Current Number
4.3.3 Next Number