Results 1 to 3 of 3

Thread: [RESOLVED] Array of my Student Class

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Resolved [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.

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Array of my Student Class

    but I'm not sure where to put it.
    vb Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.     Dim stud as new Student
    3.     stud.FirstName = "Joe"
    4.     stud.LastName = "Mama"
    5.     s(0) = stud
    6. End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: Array of my Student Class

    Well paint me purple and call me happy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width