need your help about an array macro in WORD. - TechRepublic
Question
September 8, 2007 at 04:59 AM
melodytang0214

need your help about an array macro in WORD.

by melodytang0214 . Updated 18 years, 10 months ago

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

This discussion is locked

All Comments