K
Keith(Southend)
http://msdn.microsoft.com/en-us/library/3akccs5d.aspx
To create a collection of objects...
I've added the code to Form1.vb PlayerTest but I get 5 Errors all as follws:
Name 'team' is not declared.
I was thinking I need to add 'team' as a declaration at the top, but
this didn't seem to work. I'm sure I've followed the whole tutorial
correctly.
Team.add (x4) & SelectedPlayer = team(Trim(ComboBox1.SelectedItem)).
<snip>
Public Class Form1
Dim player1 As New Persons.Players
Dim player2 As New Persons.Players
Dim player3 As New Persons.Players
Dim player4 As New Persons.Players
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
With player1
.FirstName = "Andrew"
.LastName = "Davis"
.Number = 43
.Position = "Shortstop"
End With
With player2
.FirstName = "Robert"
.LastName = "Brown"
.Number = 11
.Position = "Catcher"
End With
With player3
.FirstName = "Jeff"
.LastName = "Smith"
.Number = 52
.Position = "First Base"
End With
With player4
.FirstName = "Chris"
.LastName = "Mayo"
.Number = 22
.Position = "Pitcher"
End With
Team.Add(player1, player1.Position)
team.Add(player2, player2.Position)
team.Add(player3, player3.Position)
team.Add(player4, player4.Position)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox(player1.Position & " " & player1.FullName & _
" is now at bat.")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MsgBox(player2.Position & " " & player2.FullName & _
" is on deck.")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
Dim SelectedPlayer As Persons.Players
' The Trim function deletes spaces at the beginning and
' at the of the string.
SelectedPlayer = team(Trim(ComboBox1.SelectedItem))
MsgBox("Playing " & ComboBox1.SelectedItem & " is " & _
SelectedPlayer.FullName & "!")
End Sub
End Class
<snip>
I'm sure this is basic, but it's got my stuck at this minute :-(
Many thanks
To create a collection of objects...
I've added the code to Form1.vb PlayerTest but I get 5 Errors all as follws:
Name 'team' is not declared.
I was thinking I need to add 'team' as a declaration at the top, but
this didn't seem to work. I'm sure I've followed the whole tutorial
correctly.
Team.add (x4) & SelectedPlayer = team(Trim(ComboBox1.SelectedItem)).
<snip>
Public Class Form1
Dim player1 As New Persons.Players
Dim player2 As New Persons.Players
Dim player3 As New Persons.Players
Dim player4 As New Persons.Players
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
With player1
.FirstName = "Andrew"
.LastName = "Davis"
.Number = 43
.Position = "Shortstop"
End With
With player2
.FirstName = "Robert"
.LastName = "Brown"
.Number = 11
.Position = "Catcher"
End With
With player3
.FirstName = "Jeff"
.LastName = "Smith"
.Number = 52
.Position = "First Base"
End With
With player4
.FirstName = "Chris"
.LastName = "Mayo"
.Number = 22
.Position = "Pitcher"
End With
Team.Add(player1, player1.Position)
team.Add(player2, player2.Position)
team.Add(player3, player3.Position)
team.Add(player4, player4.Position)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox(player1.Position & " " & player1.FullName & _
" is now at bat.")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MsgBox(player2.Position & " " & player2.FullName & _
" is on deck.")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
Dim SelectedPlayer As Persons.Players
' The Trim function deletes spaces at the beginning and
' at the of the string.
SelectedPlayer = team(Trim(ComboBox1.SelectedItem))
MsgBox("Playing " & ComboBox1.SelectedItem & " is " & _
SelectedPlayer.FullName & "!")
End Sub
End Class
<snip>
I'm sure this is basic, but it's got my stuck at this minute :-(
Many thanks