0

Public Property inputChordsUser As String()

...Later in the code

            Dim Final As String = inputtedChord & LegitFinalExtensions
            CounterPublic += 1
            SendChords(Final, CounterPublic)
        End If

    End Sub
    Public Sub SendChords(ByRef Final As String, ByRef CounterPublic As Integer)
        inputChordsUser(CounterPublic) = Final
    End Sub
End Class

I'm getting a NullReferenceException Thrown at the SendChords Sub. From what I can see, inputChordsUser is set to Nothing. Duh. I'm not trying to use it, i'm trying to set it. Why is this? I've tried providing inputChordsUser as an argument with the call, but nothing. Any good fixes?

2
  • You need to provide a minimal reproducible example that demonstrates, the issue, not just a ...later in my code block out of any context. Please edit your post to provide that MRE. Commented Sep 1, 2021 at 0:28
  • You have declare an empty array, an array with no elements. When you try to add a value to an element of the array, it fails because there are not any elements. When you don't know the size of the array in advance use List(Of T) where T stands for Type. Commented Sep 1, 2021 at 1:36

1 Answer 1

1

You have not dimensioned the array inputChordsUser. You are not trying to 'set' the array, you are trying to set the element of the array at position CounterPublic. Since there is no element at that position, a NullReferenceException is thrown.

The documentation on VB Arrays can probably answer any remaining questions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.