title: Creating an array of graphic paths in vb.net
body: <p>I dont know Why I am having trouble with this, but I keep getting 'not set to an instance of an object' exception every time.</p>
  
  <p>Does this make sense?</p>
  
  <p>I have this declared in the main form</p>
  
  <pre><code>Private _Paths() As System.Drawing.Drawing2D.GraphicsPath
  </code></pre>
  
  <p>and do this in a sub</p>
  
  <pre><code> _Paths(20) = New GraphicsPath
  </code></pre>
  
  <p>But for whatever reason I get an object reference error on the second line. Any help?</p>
  
  <p>After the decleration, I want to then go ahead and add a line to the graphics path like so</p>
  
  <pre><code> _Paths(k).AddLine(x_loc(k), y_loc(k), x_loc(k + 1), y_loc(k + 1))
  </code></pre>
  
  <p>As per suggestion to use list:</p>
  
  <p>Declared in main class </p>
  
  <pre><code>Private _Paths As List(Of System.Drawing.Drawing2D.GraphicsPath)
  </code></pre>
  
  <p>using in sub</p>
  
  <pre><code>for k = 0 to 10
        'x_loc and y_loc calculations are done here
  
      _Paths.Add(New GraphicsPath)
      _Paths(k).AddLine(x_loc(k), y_loc(k), x_loc(k + 1), y_loc(k + 1))
  next
  </code></pre>
  
  <p>still get error when trying to create new instance of graphicspath</p>
  
  <p>There should be no reason this error should pop up right?
  <img src="https://i.stack.imgur.com/zo5Qo.png" alt="enter image description here"></p>
  
  <pre><code>Private _Paths As NEW List(Of System.Drawing.Drawing2D.GraphicsPath)
  </code></pre>