# Multi-Dimensional Arrays in VB.NET HELP!

**URL:** <https://forums.thehomestack.io/t/multi-dimensional-arrays-in-vb-net-help/103>\
**Category:** vb.Net\
**Created:** [December 27, 2003, 6:20pm UTC](https://forums.thehomestack.io/t/multi-dimensional-arrays-in-vb-net-help/103 "2003-12-27T18:20:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![robinhood1995](https://forums.thehomestack.io/letter_avatar_proxy/v4/letter/r/48db29/32.png) [@robinhood1995](https://forums.thehomestack.io/u/robinhood1995)\
**Post date:** [December 27, 2003, 6:20pm UTC](https://forums.thehomestack.io/t/multi-dimensional-arrays-in-vb-net-help/103/1 "2003-12-27T18:20:50Z")

</div>

Hello, I’m trying to fill a Multi-Dimensional Array and then fill the textboxes with the data.  
The array has 10 rows and 2 coloms. On the left colom I want the textboxes to show the numbers 1-10 and  
in the right colom i want the the number on the left colom squared. I’m lost.

Code follows:

Code:  
'// Populating Array…  
Dim sq(10, 2) As Integer  
Dim i, j As Integer

```
            For i = 0 To 9 
                For j = 0 To 1 
                        If j = 0 Then 
                            sq(i, j) = i 
                                    ElseIf j = 1 Then 
                             sq(i, j) = i * i 
                        End If 
                Next 
    Next 

'// Get values from Array put in TB... 
    Dim l As Integer '= 1 
    Dim obj As Object 
    Dim objtext As TextBox 
    For i = 0 To 9 
        For j = 0 To 1 
            For Each obj In Controls 
                For l = 1 To 20 
                    If TypeOf obj Is TextBox Then 
                        objtext = obj 

                        If objtext.Name = ("TextBox" & l.ToString) Then 
                            obj.text = sq(i, j) 

                        End If 

                    End If 
                Next l 

            Next 

        Next 
    Next 

```

any suggestions are appreciated.  
Thanks

---

<div class="post-metadata">

**Author:** ![system](https://forums.thehomestack.io/uploads/default/original/1X/161426793bc0d8bdf0d1a6692b3e44446861cc72.jpeg) [@system](https://forums.thehomestack.io/u/system)\
**Post date:** [December 27, 2003, 6:23pm UTC](https://forums.thehomestack.io/t/multi-dimensional-arrays-in-vb-net-help/103/2 "2003-12-27T18:23:04Z")

</div>

I think this can be cleaned up a little

Code:  
Dim sq(9, 1) As Integer  
Dim tb() As TextBox = {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6, TextBox7, TextBox8, TextBox9, TextBox10, \_  
TextBox11, TextBox12, TextBox13, TextBox14, TextBox15, TextBox16, TextBox17, TextBox18, TextBox19, TextBox20}

```
    Dim i As Integer 

    For i = 0 To 9 
        sq(i, 0) = i + 1 
        sq(i, 1) = (i + 1) * (i + 1) 
        tb(i * 2).Text = sq(i, 0).ToString 
        tb(i + (i + 1)).Text = sq(i, 1).ToString 
    Next i

```

Note that your array is one to big in both dimensions. Also note that this assumes you have 20 textboxes named as TextBox\<x\> from 1-20. If that’s not the case, simply replace the Dim tb()… with the correct names.
