Page 1 of 1

# Rich text box feeding into one dimension of a multi-dimensional array?

Posted 10 March 2013 - 07:42 PM

Ok, so i'm still a newbee, but i'm learning.

I understand how to feed an array from a user-entered Rich Text Box, via the very simple code below.

```dim temparray(25) as string
.
.
.
.
temparray = RichTextBox1.Lines
.

```

but, if i need to define a multi-dimension array:
```dim temparray(16, 25) as string

```

I want the user to enter text into the rich text box and fill up each of the 16 groups one at a time. they should enter 25 lines, temparray(1,xx) and then click a "next" button and then fill up temparray(2,xx)

therefore i need some way to define the first dimension of the array so i know where to put the user-entered text.

The following doesn't work. it wants a second value of the index.

```temparray(IdxVal) = RichTextBox1.Lines

```

But, i don't want to give it a second value, i want the user-entered values in the rich text box to be the second index.

i tried googling this, but it's hard to even know how to search for this.

Thanks!
Mike

Is This A Good Question/Topic? 0

## Replies To: Rich text box feeding into one dimension of a multi-dimensional array?

### #2 modi123_1 • • Suitor #2
•    Reputation: 14860
• Posts: 59,289
• Joined: 12-June 08

## Re: Rich text box feeding into one dimension of a multi-dimensional array?

Posted 10 March 2013 - 08:24 PM

Quote

I want the user to enter text into the rich text box and fill up each of the 16 groups one at a time. they should enter 25 lines, temparray(1,xx) and then click a "next" button and then fill up temparray(2,xx)

therefore i need some way to define the first dimension of the array so i know where to put the user-entered text.

Keep an integer counter and use that as your first dimension for the array...

```        '-- make the array and fill it with emty strings.
Dim foo(,) As String = {{String.Empty, String.Empty, String.Empty}, {String.Empty, String.Empty, String.Empty}, {String.Empty, String.Empty, String.Empty}}

'-- populate the array.
For i As Int32 = 0 To 2
For a As Int32 = 0 To 2
foo(i, a) = "test" + i.ToString + a.ToString
Next
Next

'-- our counter
Dim lCounter As Int32 = 0
'-- display what we have.
For i As Int32 = 0 To 2
Console.Write(foo(lCounter, i) + " ")
Next
Console.Write(Environment.NewLine)

'-- go to the next row
lCounter += 1
For i As Int32 = 0 To 2
Console.Write(foo(lCounter, i) + " ")
Next
Console.Write(Environment.NewLine)

'-- go to the next row
lCounter += 1
For i As Int32 = 0 To 2
Console.Write(foo(lCounter, i) + " ")
Next
Console.Write(Environment.NewLine)
```

## Re: Rich text box feeding into one dimension of a multi-dimensional array?

Posted 11 March 2013 - 07:49 PM

So, i guess i don't understand that response. The problem is not how to fill the array, it's how to fill the array with multiple lines from a rich text box.

So, i guess some more background is in order. i have 16 groups. each group can have UP TO 25 strings, but most likely less. all 16 groups can each have different number of strings.

temparray = RichTextBox1.Lines worked perfectly on a 1-dimension array, because the number of strings can be anywhere up to 25. UBound(TempArray) could read the number of strings stored.

So, i came up with a plan that seems to work to fill the array. I just do it in 2 steps.
```        TempArray = RichTextBox1.Lines
For i = 1 To UBound(TempArray)
MultiArray(IdxVal, i) = temparray(i)
Next

```

Simple, right?

now, on the other end, i need to extract data from one group of this MultiArray, and put it back into a single-dimension array. Now i'm stuck there. Because i don't know the number of items stored in the second dimension of the array, i need to find some way to determine this, so i can successfully extract exactly the right number of items.

I read that Ubound(MultiArray,2) should theoretically work, except MultiArray(1,xx) and MultiArray(2,xx) can have different number of items for xx. which first index value will Ubound(MultiArray,2) use to determine length of the second dimension? the first one? whichever returns the highest number?

So, perhaps the real question is a more generic one, how do i use functions that read, write and query single-dimension arrays, with a multi-dimension array, where one of the index values is known, and stuff needs to be determined about only the other index value?

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }