Question Locked

need your help about an array macro in WORD.

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

need your help about an array macro in WORD.
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"

UserForm1.Show

End Sub

Sub PrintAllMarks()

ActiveDocument.Bookmarks("Start").Select

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 !!!

1 reply

This discussion is closed to new replies.