crazyfisherrr


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



Re: need help for an array macro in word

bi-lya


Try it

Code Snippet

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






Re: need help for an array macro in word

crazyfisherrr

thanks so much !!
it is working perfectly SmileSmile

I will do more study about VBA now Smile