0

I am trying to add each numeric digit in a textbox to a list(of Integer) but I am required to use integer.Parse to get it into the correct format, but upon doing so receive a "Object reference not set to an instance of an object" error. My code is as follows:

Dim key As List(Of Integer)
Dim digit As Integer

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    For Each c As Char In TextBox1.Text
        digit = Integer.Parse(c)
        key.Add(digit)
    Next
End Sub
Ghoohio
  • 3
  • 2

1 Answers1

1

You must initialize an instance of the list. This is done using the New keyword:

Dim key As New List(Of Integer)

Read more about the New keyword

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
Visual Vincent
  • 18,045
  • 5
  • 28
  • 75