Link to home
Start Free TrialLog in
Avatar of KarlTheHopeless
KarlTheHopelessFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Where and How have you declared SList
Avatar of KarlTheHopeless

ASKER

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



ASKER CERTIFIED SOLUTION
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
PERFECT

Thank Jacko
Thanks Jacko.