0

I'm using a list in VB, which is declared in the public class. When I try to use the count of this list (e.g. list.Count) in an If Statement within a private sub, I get a Null Reference Exception error. I'm not sure how to set the Count to 0 to declare it. Does anyone know how I can fix this.

  • 1
    I still think you're experiencing the same error as in your previous question. Have you heard of the [**New keyword**](https://msdn.microsoft.com/en-us/library/77s47661.aspx)? -- You cannot modify the `Count` variable by the way, and it is your entire list that is null, not just `Count`. – Visual Vincent Aug 23 '16 at 06:52
  • 1
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Visual Vincent Aug 23 '16 at 06:52
  • Check to make sure your list isnt empty before using it. Using another if statement before `If list.count = 0 Then`, or edit your current if statement to check if list is empty first – Cal-cium Aug 23 '16 at 11:36
  • @Cal-cium : Being _empty_ is not the same as being _null_. But for for the record, he's not using the `New` keyword. See [his previous question](http://stackoverflow.com/questions/39083940/identify-object-reference-not-set-to-an-instance-of-an-object-error). – Visual Vincent Aug 23 '16 at 12:23
  • @VisualVincent my bad, i didn't see this question, I was thinking of another question he posted and got mixed up. And yes you are correct they are not the same. – Cal-cium Aug 23 '16 at 12:54

0 Answers0