View Full Version : need help for an array macro in word

09-08-2007, 08:44 AM
Dear all,
I am a beginner of VBA programming and I have some problems with an array macro,plz help !!!

the array stores student ID and student Name and the macro will enable me to enter the student ID and student Mark in a form, and it will show up " student *** has a mark of ***".
this is my script:

Public arStuID(8) As String
Public arStudMark(8) As Integer

Sub startit()

arStuID(1) = "Tim"
arStuID(2) = "Jim"
arStuID(3) = "Dim"
arStuID(4) = "Tam"
arStuID(5) = "Tom"
arStuID(6) = "Tum"
arStuID(7) = "Lim"
arStuID(8) = "Nee"


End Sub

Sub PrintAllMarks()


For x = 1 To 8
If x = arStuID(x) Then
Selection.TypeText "Student " & arStuID(x) _
& " has a mark of " & arStudMark(x) & "." & vbCrLf
End If
Next x

End Sub

but the problem is even if I didn't supply a certain student ID and his mark, the document still show a line" student has a mark of 0"
how should I code to show only the inputed student ID and mark ??

thanks !!!