' Basic Programming ' Ch. 6 Demo Program #10 ' Written by Mr. Minich ' purpose - to illustrate the use of arrays
Option Explicit Dim mintScores(20) As Integer ' all student's exam scores
' mintScores is a module-level array. If it was declared as a local ' array variable within one of the event procedures, it's elements ' would be cleared at the end of each event procedure. Private Sub cmdDisplay_Click()
Dim J As Integer ' loop variable lstAllScores.Clear ' clear the list box items before reinserting For J = 1 To 20 ' storing array elements into list box lstAllScores.AddItem mintScores(J) Next J End Sub Private Sub cmdEnter_Click() Dim intStudentID As Integer ' student ID number Dim intExamScore As Integer ' student exam score intStudentID = Val(txtStudentID.Text) ' converting inputs to numeric values intExamScore = Val(txtScore.Text) mintScores(intStudentID) = intExamScore ' assigning the score to the correct ' index position of the array txtStudentID.Text = "" ' clearing the user's inputs txtScore.Text = "" End Sub