How can I read values from multiple textboxes into a 2-D array in VB.NET?

In summary, the user is struggling to create a procedure that can read in values from multiple textboxes in a 2-D array. They have attempted to use a for/next loop, but are stuck and wondering if there is an easier way to accomplish this. They mention that control arrays were easier to use in VB6, but have been removed in VB.NET. They suggest searching on VB.NET forums for potential solutions.
  • #1
debwaldy
38
0
Hi I am a new-comer to VB.Net & I am working with arrays at the moment.i want to write a procedure that accepts two 2-D arrays(max size being a 4*4 matrix).
i don't know how i could get the procedure to read in these values from the sixteen different textboxes i have created...i started using a for/next loop to go through each row as shown below:

Dim i, j, n, m As Integer
Dim a As Double(,)
a = New Double(i, j) {}
For i = 0 To a.GetUpperBound(i)
For j = 0 To a.GetUpperBound(j)
a(i, j) = TextBox

its here that I am stuck i want it to go through each row of textboxes row by row and read in the values input by the user.would some sort of inner loop again work...or is there a much easier way to do this...any help is much appreciated :biggrin:
 
Computer science news on Phys.org
  • #2
debwaldy said:
Hi I am a new-comer to VB.Net & I am working with arrays at the moment.i want to write a procedure that accepts two 2-D arrays(max size being a 4*4 matrix).
i don't know how i could get the procedure to read in these values from the sixteen different textboxes i have created...i started using a for/next loop to go through each row as shown below:

Dim i, j, n, m As Integer
Dim a As Double(,)
a = New Double(i, j) {}
For i = 0 To a.GetUpperBound(i)
For j = 0 To a.GetUpperBound(j)
a(i, j) = TextBox

its here that I am stuck i want it to go through each row of textboxes row by row and read in the values input by the user.would some sort of inner loop again work...or is there a much easier way to do this...any help is much appreciated :biggrin:
Yeah, this is a frustration w/ VB.NET, after such things (called "control arrays") that were so easy in VB6 got tossed out in VB.NET

There ARE ways to create control arrays in VB.NET but it's quite ugly. I suggest a search on one of the VB.NET forums. The details are just too messy for me to want to go into here in a post.
 
  • Like
Likes Greg Bernhardt

Related to How can I read values from multiple textboxes into a 2-D array in VB.NET?

1. What is an array in VB programming?

An array in VB programming is a data structure that allows you to store multiple values of the same data type in a single variable. It is useful for organizing and manipulating large sets of data.

2. How do you declare and initialize an array in VB programming?

To declare an array in VB programming, you use the Dim keyword followed by the name of the array and the data type of its elements. For example, Dim numbers() As Integer. To initialize an array, you can use the Array function or use curly brackets to specify the values. For example, numbers = {1, 2, 3, 4, 5}.

3. How do you access elements in an array in VB programming?

You can access elements in an array by using the index of the element within square brackets after the array name. For example, numbers(2) would access the third element in the array (since arrays start at index 0).

4. Can you change the size of an array in VB programming?

No, the size of an array in VB programming is fixed once it is declared. However, you can use the ReDim statement to change the size of an array, although this will erase any existing data in the array.

5. What are some common errors when working with arrays in VB programming?

Some common errors when working with arrays in VB programming include trying to access an element at an index that is out of bounds (i.e. larger than the size of the array), not declaring the array with the correct data type, or not properly initializing the array before using it.

Similar threads

  • Programming and Computer Science
Replies
11
Views
2K
  • Programming and Computer Science
Replies
4
Views
11K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
3K
  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
Replies
10
Views
25K
  • Programming and Computer Science
Replies
6
Views
5K
  • Programming and Computer Science
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
Back
Top