CaptainSolo24
New member
This is my first vb.net project in 2 years and coming from the java and c++ world it is so much easier but some things just don't work the some as you already know. My problem is I have a class called Hteam and i have an array of Hteam as public so I can use them throughout my program but the issue lies where I try to set the team name it gives the NullReference Exception
but im not sure why? I use Inputboxes in get data from user.
I was able do this in java but not vb.net!
Hteam Class
but im not sure why? I use Inputboxes in get data from user.
I was able do this in java but not vb.net!
VB.NET:
Imports System.Globalization
Public Class Form1
Public maps() As String = {"Amplified", "Assembly", "Avalanche", "Blackout", "Cold Storage", "Construct", "Epitaph", "Foundry", "Ghost Town", "Guardian", "High Ground", "Isolation", _
"Last Resort", "Lockdown", "Narrows", "Onslaught", "Orbital", "Rat's Nest", "Sandbox", "Sandtrap", "Snowbound", "Standoff", "The Pit", "Valhalla", "OTHER"}
Public teams() As Hteam
Public numTeam As Integer
Public tourType As Integer
Private Sub startB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startB.Click
Dim name As String = " "
Dim num As Integer = 0
Dim s As String
Dim n As Integer = 0
s = InputBox("Enter the number teams:", "enter", "0")
Integer.TryParse(s, numTeam)
Do While n < numTeam
teams(n).setTeam(0, 0, 0, 0, "") 'Error here
n += 1
Loop
Do While num < numTeam
name = InputBox("Enter a team name:", "enter", "Team Name")
teams(num).setTeamname(name) 'Error here
num += 1
Loop
End Sub
Hteam Class
VB.NET:
Public Class Hteam
Private teamName As String
Private wins As Integer
Private numMembers As Integer
REM private members[] teamMembers = new members[numMembers];
Private losses As Integer
Private ties As Integer
Public Sub New()
setTeam(0, 0, 0, 1, "")
End Sub
Public Sub New(ByVal w As Integer, ByVal l As Integer, ByVal t As Integer, ByVal nm As Integer, ByVal tname As String)
setTeam(w, l, t, nm, tname)
End Sub
Public Sub setTeam(ByVal w As Integer, ByVal l As Integer, ByVal t As Integer, ByVal nm As Integer, ByVal tname As String)
teamName = tname
If ((nm > 0) And (nm < 5)) Then
numMembers = nm
Else
numMembers = 1
End If
If (w >= 0) Then
wins = w
Else
wins = 0
End If
If (l >= 0) Then
losses = l
Else
losses = 0
End If
If (t >= 0) Then
ties = t
Else
ties = 0
End If
End Sub
' public void setMembers()
' {
' for(int i = 0; i < numMembers;i++)
' {
' teamMembers[i].setName("Mem");
' }
' }
Public Sub setTeamname(ByVal tn As String)
teamName = tn
End Sub
Public Sub setNummem(ByVal n As Integer)
numMembers = n
End Sub
Public Sub addWin()
wins = wins + 1
End Sub
Public Sub addLoss()
losses = losses + 1
End Sub
Public Sub addTie()
ties = ties + 1
End Sub
' Public Property getMembername(int n)
' return teamMembers[n].getName();
Public Property getWins() As Integer
Get
Return wins
End Get
Set(ByVal value As Integer)
End Set
End Property
Public Property getLosses() As Integer
Get
Return losses
End Get
Set(ByVal value As Integer)
End Set
End Property
Public Property getTies() As Integer
Get
Return ties
End Get
Set(ByVal value As Integer)
End Set
End Property
Public Property getTeamname() As String
Get
Return teamName
End Get
Set(ByVal value As String)
End Set
End Property
Public Property getNummem() As Integer
Get
Return numMembers
End Get
Set(ByVal value As Integer)
End Set
End Property
End Class