我运行我的代码,我在try-catch的消息框中收到错误。错误是"对象引用未设置为对象的实例"请帮助我完全陷入困境,直到这个问题得到解决!
Public Class Development
Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Call Deck.CreateUnmixedDeckIdList()
Catch ex As Exception
MsgBox("Failed" & vbCrLf & ex.Message)
End Try
For Each x As Integer In Deck.UnMixedIDDeck
ListBox1.Items.Add(x & vbCrLf)
ListBox1.Items.Add(x)
Next
End Sub
Private Sub ShowMixedDeckIds(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Deck.SuffleDeck()
For Each x As String In Deck.MixedIDDeck
ListBox1.Items.Add(x & vbCrLf)
Next
End Sub
End Class
Public Class Deck
Public Shared UnMixedIDDeck, MixedIDDeck As List(Of Integer)
Public Shared Sub CreateUnmixedDeckIdList()
For i As Integer = 1 To 52
UnMixedIDDeck.Add(i)
Development.ListBox1.Items.Add(i)
Next
End Sub
'SuffleDeck
Public Shared Sub SuffleDeck()
MixedIDDeck = RandomIDOrder(UnMixedIDDeck)
End Sub '
'Returns a list of numbers from the lenth of the given list
Private Shared Function RandomIDOrder(ByVal List As List(Of Integer)) As List(Of Integer)
Dim RandomList As New List(Of Integer)
Dim R As New Random
'Runs untill RandomList has the same lenth as GIVEN list
Do While Not RandomList.Count = List.Count
Dim S As String = List(R.Next(0, List.Count))
'Checks to make sure value is not in list all ready. If it happen to be in the list it will not add it again and go back to lst While loop!
If Not RandomList.Contains(S) Then
RandomList.Add(S)
End If
Loop
'Returns the new list of non repeating integers depending on the list you gave.
Return RandomList
End Function
End Class
Public Class Card
Public Function GetCardTitle(Id As Integer)
Dim CardName As String
CardName = ""
Return CardName
End Function
End Class