title: Visual Basic Arrays
body: <p>Hello I am having a hard time with arrays in visual basic. This is a simple console application (I am trying to get the hang of the syntax before I move on to gui) and all this program does is use two types of arrays jagged and the regular type. This console application is a times table generator i.e enter in 5 columns and 5 rows to make a 5X5 times table. The program is not finished yet and I know the times table wont generate right with this code so far but what I need help with is how to populate arrays in VB. Where my problem is in this sub</p>
  
  <p>SUB:</p>
  
  <pre><code>Sub arrayPopulate(ByVal regularArray(,) As Integer, ByVal columns As Integer, ByVal rows As Integer)
          Dim i As Integer
          Dim j As Integer
          Dim mult As Integer
  
          For i = 0 To rows
              For j = 0 To columns
                  mult = (i + 1) * (j + 1)
                  regularArray(j, i) = mult
              Next
          Next
  
      End Sub
  </code></pre>
  
  <p>Specifically the line <code>regularArray(j, i) = mult</code> I would have thought it be simple the arrays element is set <code>=</code> to what ever the <code>mult</code> is and the for loops would cover the 2d array. What am I doing wrong and how could I fix it or do it better?</p>
  
  <p>FULL CODE:    </p>
  
  <pre><code> Module Module1
      Sub Main()
          'Declarations
          Dim awns As Char
          Dim switchOption As Integer
          Dim columns As Integer
          Dim rows As Integer
          Dim regularArray(columns, rows) As Integer 
  
          'Starting Prompts
          Console.WriteLine("Hello this program will create a times table with")
          Console.WriteLine("user inputs in terms of rows and columns.")
          Console.WriteLine("Pick between these two options.")
          Console.WriteLine("Option 1: Times table with a regular array.")
          Console.WriteLine("Option 2: Times table with a jagged array.")
  
          Do
              Console.Write("Which option do you wnat? ")
              switchOption = Console.ReadLine
  
              Console.WriteLine("How many columns do you wnat? ")
              columns = Console.ReadLine
              columns = columns - 1
              Console.WriteLine("How many rows do you wnat? ")
              rows = Console.ReadLine
              rows = rows - 1
              Select Case switchOption
                  Case 1
                      arrayPopulate(regularArray, columns, rows)
                      Dim i As Integer
                      Dim j As Integer
  
                      For j = 0 To rows
                          For i = 0 To columns
                              Console.WriteLine("{0}: ", regularArray(i, j))
                          Next
                      Next
  
                  Case 2
                      Console.WriteLine("Test")
  
              End Select
  
              Console.WriteLine("Do you want to run again y/n?")
              awns = Console.ReadLine()
          Loop Until awns = "n"
      End Sub
  
      Sub arrayPopulate(ByVal regularArray(,) As Integer, ByVal columns As Integer, ByVal rows As Integer)
          Dim i As Integer
          Dim j As Integer
          Dim mult As Integer
  
          For i = 0 To rows
              For j = 0 To columns
                  mult = (i + 1) * (j + 1)
                  regularArray(j, i) = mult
              Next
          Next
  
      End Sub
  End Module
  </code></pre>