title: How to initialize an array in a structure
body: <p>I am trying to initialize an array and assign values, but I am having problems</p>
  
  <pre><code>Public Structure test1
      &lt;VBFixedArray(6)&gt; Dim Id() As String
      Public Sub initialize()
          ReDim Id(6)
      End Sub
  End Structure
  
  Dim myvalues() as test1
  ...
  ReDim myvalues(10)
  </code></pre>
  
  <p>I am trying to accomplish this with the following</p>
  
  <pre><code>For i as short = 0 to 10
      myvalues(i).Id(1) = "V"
      myvalues(i).Id(2) = "H"
      ...
      myvalues(i).Id(6) = "J"
  next i
  </code></pre>
  
  <p>This is not working though and I am not sure of the proper implementation?</p>
  
  <p>EDIT:</p>
  
  <pre><code>Imports Microsoft.VisualBasic
  Module Module1
  Structure test1
      &lt;VBFixedArray(6)&gt; Dim Id() As String
      Public Sub initialize()
          ReDim Id(6)
          For im As Integer = 0 To 6
              Id(im) = ""
          Next im
      End Sub
  End Structure
  Sub Main()
      Dim i As Integer
      Dim myvalues() As test1
      ReDim myvalues(10)
      For Each oTest As test1 In myvalues
          ' Initialize the structure 
          ReDim myvalues(10)
          oTest.initialize()
          ' Now loop through the array based on the bounds it was configured for
          'initialize to empty string(NOT ABLE TO ASSIGN TO&gt; myvalues(i).Id(j))
          'I Get ERROR&gt;&gt;&gt;Object reference not set to an instance of an object&lt;&lt;&lt;&lt;&lt;
          'For i = 0 To 10
          For j As Integer = oTest.Id.GetLowerBound(0) To oTest.Id.GetUpperBound(0)
              ' Set the values in a case statement so that alterations to the size of the index won't break your code.
              Select Case j
                  Case 0
                      oTest.Id(j) = "A"
                      myvalues(i).Id(j) = "A"
                  Case 1
                      oTest.Id(j) = "B"
                      'myvalues(i).Id(j) = "B"
                  Case 2
                      oTest.Id(j) = "C"
                      'myvalues(i).Id(j) = "C"
                  Case 3
                      oTest.Id(j) = "D"
                      'myvalues(i).Id(j) = "D"
                  Case 4
                      oTest.Id(j) = "E"
                      'myvalues(i).Id(j) = "E"
                  Case 5
                      oTest.Id(j) = "F"
                      'myvalues(i).Id(j) = "F"
                  Case 6
                      oTest.Id(j) = "G"
                      'myvalues(i).Id(j) = "G"
              End Select
          Next j
          'Next i
      Next 'oTest
          'assign&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; NOT WORKING&gt;&gt;&gt;&gt;
          '&lt;&lt;Id() is not set to &lt;empty string&gt; it is "Nothing"  I GET ERROR (91) next line and after
          'What am I doing wrong?
          For i = 0 To 10
          Console.WriteLine(myvalues(i).Id(0), myvalues(i).Id(1), myvalues(i).Id(2), myvalues(i).Id(3), myvalues(i).Id(4), myvalues(i).Id(5), myvalues(i).Id(6))
      Next i
  End Sub
  End Module
  </code></pre>