title: VB.net Increment variables possible?
body: <p>I am trying to find a better way to write this code but I can't figure out how to make this cleaner.  In other languages I have used in the past I am able to increment the variables with a loop instead  of having to apply the same code to several variables.  I suppose I am looking for something like this where the variable name itself is being changed or created using the loop:</p>
  
  <pre><code>Dim IP0 As String = ""
      While IP0 &lt; 5
          IP0 = IP0.Remove(index).Trim
          index = IP2.IndexOf(" "c)
          IP0 = IP0 + 1
      End While
  </code></pre>
  
  <p>In the above example, I would like the "+1" to actually add to the variable itself.  So "IP0" would become "IP1", then "IP2" and so on.  This does not compile obviously, is there a way to do this is VB.net?
    Here are a couple snippets of my current project that I would like to apply this logic to:</p>
  
  <h1>1</h1>
  
  <pre><code>Dim IP1, IP2, IP3, IP4, IP5, IP6, IP7, IP8, IP9 As String
  IP1 = IP1.Remove(index).Trim
  index = IP2.IndexOf(" "c)
  IP2 = IP2.Remove(index).Trim
  index = IP3.IndexOf(" "c)
  IP3 = IP3.Remove(index).Trim
  index = IP4.IndexOf(" "c)
  IP4 = IP4.Remove(index).Trim
  index = IP5.IndexOf(" "c)
  IP5 = IP5.Remove(index).Trim
  index = IP6.IndexOf(" "c)
  IP6 = IP6.Remove(index).Trim
  index = IP7.IndexOf(" "c)
  IP7 = IP7.Remove(index).Trim
  index = IP8.IndexOf(" "c)
  IP8 = IP8.Remove(index).Trim
  index = IP9.IndexOf(" "c)
  IP9 = IP9.Remove(index).Trim
  </code></pre>
  
  <h1>2</h1>
  
  <pre><code>Using writer As StreamWriter = New StreamWriter("C:\tempFiles\bigBatch.bat")
  
          writer.Write(
              "ping -a " &amp; IP1 &amp; " -n 1 &gt; c:\tempFiles\IP1.txt" &amp; vbNewLine &amp;
              "ping -a " &amp; IP2 &amp; " -n 1 &gt; c:\tempFiles\IP2.txt" &amp; vbNewLine &amp;
              "ping -a " &amp; IP3 &amp; " -n 1 &gt; c:\tempFiles\IP3.txt" &amp; vbNewLine &amp;
              "ping -a " &amp; IP4 &amp; " -n 1 &gt; c:\tempFiles\IP4.txt" &amp; vbNewLine &amp;
              "ping -a " &amp; IP5 &amp; " -n 1 &gt; c:\tempFiles\IP5.txt" &amp; vbNewLine &amp;
              "ping -a " &amp; IP6 &amp; " -n 1 &gt; c:\tempFiles\IP6.txt" &amp; vbNewLine &amp;
              "ping -a " &amp; IP7 &amp; " -n 1 &gt; c:\tempFiles\IP7.txt" &amp; vbNewLine &amp;
              "ping -a " &amp; IP8 &amp; " -n 1 &gt; c:\tempFiles\IP8.txt" &amp; vbNewLine &amp;
              "ping -a " &amp; IP9 &amp; " -n 1 &gt; c:\tempFiles\IP9.txt" &amp; vbNewLine)
      End Using
  </code></pre>
  
  <h1>3</h1>
  
  <pre><code>Dim IP1, IP2, IP3, IP4, IP5, IP6, IP7, IP8, IP9 As String
      IP1 = thisArray(3).Trim
      IP2 = thisArray(4).Trim
      IP3 = thisArray(5).Trim
      IP4 = thisArray(6).Trim
      IP5 = thisArray(7).Trim
      IP6 = thisArray(8).Trim
      IP7 = thisArray(9).Trim
      IP8 = thisArray(10).Trim
      IP9 = thisArray(11).Trim
  </code></pre>