Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

VBA- creating 1D array using 2D array

Options
  • 27-12-2013 8:06pm
    #1
    Registered Users Posts: 3,608 ✭✭✭


    Hello,

    I'm trying to learn to program in VBA and have basically no experience up to this point.

    I have a 9x9 2D array called solveGrid. I want to use this 2D array to populate a series of 1D arrays that are the rows of solveGrid.

    Here is a snippet from my code:
    'make each row a 1D array
        Dim row1(1 To 9) As Integer
        Dim row2(1 To 9) As Integer
        Dim row3(1 To 9) As Integer
        Dim row4(1 To 9) As Integer
        Dim row5(1 To 9) As Integer
        Dim row6(1 To 9) As Integer
        Dim row7(1 To 9) As Integer
        Dim row8(1 To 9) As Integer
        Dim row9(1 To 9) As Integer
        
        'Populate each row array
        Dim g As Integer
        g = 1
        
            For g = 1 To 9
                row1(g) = solveGrid(1, g)
                row2(g) = solveGrid(2, g)
                row3(g) = solveGrid(3, g)
                row4(g) = solveGrid(4, g)
                row5(g) = solveGrid(5, g)
                row6(g) = solveGrid(6, g)
                row7(g) = solveGrid(7, g)
                row8(g) = solveGrid(8, g)
                row9(g) = solveGrid(9, g)
                g = g + 1
            Next g
    

    The above will execute but is not populating the 1D arrays as I intend. Could anyone suggest where the problem might lie?

    Thanks


Comments

  • Technology & Internet Moderators Posts: 28,799 Mod ✭✭✭✭oscarBravo


    I haven't done any VB in hundreds of years, but from what I recall of For...Next, you don't need to increment the g variable (g = g + 1); it's done for you by the For loop construct.


  • Registered Users Posts: 3,608 ✭✭✭breadmonkey


    Thank you that did the trick!


Advertisement