user1570048
user1570048

Reputation: 880

vb.net my.settings arraylist is not an instance of object

If My.Settings.Sup1 Is Nothing Then
        My.Settings.Sup1 = New Collections.ArrayList
        My.Settings.Sup1.Add(0)' array index can't be negative or less than 0
        My.Settings.Sup1.Add(0)
        My.Settings.Sup1.Add(0)
        My.Settings.Sup1.Add(0)
    End If

why would i even get this exception in the commented line, is there anything wrong with the above code

i tried insert and assigning a value to the current index and still i am getting the exception

Upvotes: 1

Views: 2350

Answers (2)

Mark Hall
Mark Hall

Reputation: 54532

I added an User Setting on the Project Properties → Settings Tab of Type System.Collections.ArrayList and it works as expected. Not sure what your problem is your code looks fine, I would double check your Type and make sure it is correct.

enter image description here


enter image description here

Upvotes: 1

Joe Healy
Joe Healy

Reputation: 5817

Ran this in a WPF project. I couldn't quit figure out how you got an array list under my app settings stuff so I used a System.Collection.Specialized.StringCollection. [right-mouse] "My Project", go to Settings, and add Sup1 in there as System.Collection.Specialized.StringCollection. Leave value blank.

In the debugger it iterates over all the lines below just fine, no exceptions.

    Public Sub New()
    'assuming sup1 is supposed to be an System.Collection.Specialized.StringCollection as set in Project Properties
            If My.Settings.Sup1 Is Nothing Then
                ' -- replaced w string collection -- My.Settings.Sup1 = New Collections.ArrayList
                My.Settings.Sup1 = New System.Collections.Specialized.StringCollection
                My.Settings.Sup1.Add(0) ' array index can't be negative or less than 0
                My.Settings.Sup1.Add(0)
                My.Settings.Sup1.Add(0)
                My.Settings.Sup1.Add(0)
            End If
    End Sub

Upvotes: 0

Related Questions