Tag Archives: Array

One Dimensional Arrays

A 1D array is a data structure that can be thought of like a list. For example if you were asked to create a program that stores five names you might think that you could use 5 variables, what about a program that stores 20 or even 1000?

To create an array we use the DIM command but we add in a new piece of information.

DIM Number(5) as Integer

Continue reading One Dimensional Arrays

A couple of questions from today

Jonathan asked me a couple of very good questions today and I thought I would share my answers.

What is the difference between a linear CCD and a Array CCD?

  • A linear CCD is used in scanners and consists of a row of CCDs that moves down the document.
  • A CCD array is used in digital cameras and consists of a grid of CCDs as shown in this picture

Is it just CCDs that are used in digital cameras.

  • Some cameras use cheaper CMOS sensors, these sensors are not as fast and do not produce the same quality as a CCD. Wikipedia has this to say.

What does WRL stand for

  • This has taken a fair bit of research and the answer was on the blog the whole time… “World Description Language”. Personally I take the view of a lot of the websites WRL is the file suffix for VRML files and stands for WoRLd.

So with all this on the blog I updated the Multimedia Glossary, after all what else did I have to do.

You learn something new every day

I didn’t know that Visual Basic Express Edition could handle a string as an Array. Some programming languages require you to use individual characters and then create an array of these to create a string, so I guess that is what is going on. I also found this article on spiting and joining arrays.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim UserString As String
End Sub
Private Sub GetString(ByRef UserString As String)
UserString = InputBox(“What is your name”)
End Sub
Private Sub DisplayString(ByVal UserString As String)
For Counter = 0 To (Len(UserString) – 1)
End Sub
So for the string “John” we get the following
VB5CCE does not do this, we get the following error

VB Program for Displaying the Average of 20 Marks

Below is the program from today’s lesson. It is not completed, I would like you to Change the program to display the average with two decimal places. Please add your solution with a comment below.

Private Sub CmdStart_Click()
'load an Array with data from a list box
'list box is hidden on the form
'List Boxes count from 0 so add a heading to the fist item
Dim IntNumber(20) As Integer
Dim StrName(20) As String
Dim intavg As Integer
Call Load_Array(IntNumber(), StrName())
Call Calc_Average(IntNumber(), intavg)
Call Display_Array(IntNumber(), StrName(), intavg)
End Sub

Private Sub Load_Array(ByRef Number() As Integer, ByRef StrName() As String)
Dim Counter As Integer 'local Variable
For Counter = 1 To 20
Number(Counter) = LstNumbers.List(Counter)
StrName(Counter) = LstNames.List(Counter)
End Sub

Private Sub Calc_Average(ByRef IntNumber() As Integer, ByRef intavg As Integer)
Dim IntSum As Integer
For Counter = 1 To 20
IntSum = IntSum + IntNumber(Counter)
intavg = IntSum / 20
End Sub

Private Sub Display_Array(ByRef Number() As Integer, ByRef StrName() As String, ByVal intavg)
'Standard procedure as used in previous programs
Dim Counter As Integer 'local Variable
For Counter = 1 To 20
Form1.Print StrName(Counter) & " scored " & Number(Counter) & "%"
Form1.Print "Average = " & intavg & "%"
End Sub

Introduction to Arrays

Today’s lesson introduced 1-D arrays. The class started off by creating 3 programs.
1. Create a program to take in 3 numbers and display the sum and average.
2. modify the program to work with 5 numbers.
3. Modify the program to display the numbers after it displays the sum and average.

The class were given the main steps and asked to refine it, before starting the task. Each task was to be saved in separate folders.

The class was then asked to modify the program for 100 numbers. This led to discussion about the need for a new data type that could store a list of values, this data type is called Array.

Scratch was used to show how arrays can be used. The class then looked at the DIM command’s help page to discover how to set up an Array.

DIM IntNumber(50) as Integer

Where (50) is the number of items in the array.

The program was modified to allow entry of 100 values before the period finished.


Write the refinements for the main program given for 100 numbers.

  1. Set up Variables
  2. Get 100 values from user
  3. Calculate Average and Sum of values
  4. Display the Average, Sum and values
  5. End program