How to Add to a SortedList

Hi Everyone

Could someome please explain why I get the Error "Object reference not set to an instance of an object" in the following code ...

====================

      Dim InputFrom As String = ""
            Dim Pos As Short = 0
... ...

            For i As Int16 = 1 To 24
                  InputFrom = LineInput(Ch("QuestionAnswer"))
                  Pos = InStr(InputFrom, "/")
                  QuestionAnswer.Answer = Mid(InputFrom, Pos + 1)
                  QuestionAnswer.Question = InputFrom.Substring(0, Pos - 1)
                  SortedDict(QuestionAnswer.Answer) = QuestionAnswer.Question
                  SList.Add(QuestionAnswer.Answer, QuestionAnswer.Question)
            Next

=======================

The error occurs on the line begininng with SList.

The variables QuestionAnswer.Answer and QuestionAnswer.Question seem to be fine, in that hovering over them shows them to be correct.

Thank you

Karl
KarlTheHopelessAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul JacksonSoftware EngineerCommented:
Where and How have you declared SList
KarlTheHopelessAuthor Commented:
Hi Jacko

This is declared right at the beginning of the Class.

==============

Public Class frmpupwork
   Inherits System.Windows.Forms.Form
      Public SList As New SortedList(Of String, Object)

============

Karl



Paul JacksonSoftware EngineerCommented:
change : Public SList As New SortedList(Of String, Object)

to : Public SList As New SortedList()

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KarlTheHopelessAuthor Commented:
PERFECT

Thank Jacko
KarlTheHopelessAuthor Commented:
Thanks Jacko.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.