[RESOLVED] Array of my Student Class
I created a simple Class called Student.
Code:
Public Class Student
Property FirstName As String = ""
Property LastName As String = ""
End Class
And then I tried to create an array of Students called s. I'd like to do something simple with the names of one of the students like the following...
Code:
Public Class frmMain
Public s(0 To 10) As Student
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
s(1).FirstName = "Joe"
s(1).LastName = "Mama"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(s(1).FirstName & "'s last name is " & s(1).LastName)
End Sub
End Class
I know that I need to use the New keyword to create an instance for each s(), but I'm not sure where to put it. When I try it without the array it's easy.
Code:
Dim s As New Student
But the array of students changes things.
Re: Array of my Student Class
Quote:
but I'm not sure where to put it.
vb Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim stud as new Student
stud.FirstName = "Joe"
stud.LastName = "Mama"
s(0) = stud
End Sub
Re: Array of my Student Class
Well paint me purple and call me happy.