0

If I have an array of student test scores for multiple students(example: 5 students with 5 grades for each)

Dim aStudent1Grades() As New String = {Me.tboStudent1Grade1.Text, Me.tboStudent1Grade2.Text, Me.Student1Grade3.Text, Me.Student1Grade4.Text, Me.Student1Grade5.Text}

(create 4 other arrays for the other 4 students in the same fashion)

THEN I would like to create an array and store these 5 student arrays into that so I can loop through it and do all my data validation testing.

Something like:

Dim aAllGrades() As New Array = {aStudent1Grades(), aStudent2Grades(),        aStudent3Grades(), aStudent4Grades(), aStudent5Grades()}

I would use a For loop to loop through the array of arrays which will have another For loop inside that to loop through each aStudentGrade array to test the data.

Is storing arrays within another array possible? Thanks

4
  • Is storing arrays within another array possible? This seems like a question you could easily answer on your own through trial and error. What have you tried so far? Commented May 27, 2015 at 17:28
  • Why would you think you couldn't? Commented May 27, 2015 at 17:32
  • Oh idk, I've never tried it before. I have yet to mess with it; I will be doing it tonight, but I am just kind of planning it out in my head at the moment. Commented May 27, 2015 at 17:36
  • You may also want to think about whether the arrays are symmetric or not. It is the difference between a 2d array or a jagged array or even an array of objects/structs. Commented May 27, 2015 at 19:37

3 Answers 3

2

This is a c# example, but you should get the idea.

int[] array1= new int[4] { 44, 2, 3, 4};
int[] array2 = new int[4] { 55, 6, 33, 3};
int[] array3 = new int[4] { 77, 22, 4, 1 };
int[] array4 = new int[4] { 77, 4, 3, 3};

int[][] arrays= new int[][] {  array1,  array2,  array3,  array4 };
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the tip! Why the need for double '[ ]' for the array of other arrays?
Because it's an array of type array, not type int.
1

Sure - just make it a jagged array:

Dim aAllGrades()() As String = {aStudent1Grades, aStudent2Grades, aStudent3Grades}

Then you can loop through in a strongly-typed manner:

For Each a As String() in aAllGrades
    For Each aa As String in a
        Console.WriteLine(aa)
    Next
Next

Comments

0

I'd like to suggest to sort your Students in a class:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Create an array of 5 for the Students
        Dim Students(5) As Student  'could be a List(Of Student) so you can add a new one whenever you like without any effort
        Dim i As Integer = 0 'Just an example for useage


        For j = 0 To 5
            Students(j) = New Student
        Next

        'Add the Grades
        Students(0).Grades.Add(Me.tboStudent1Grade1.Text)
        'etc

        'An example for a loop
        For Each s In Students
            For Each g As Integer In s.Grades
                i += g 
            Next
        Next


    End Sub
End Class


Public Class Student
    Public Name As String
    Public Grades As New List(Of Integer)

    Shared Sub New()

    End Sub
End Class

2 Comments

Even better would be to suggest using a List(Of Student) so that the number of them does not have to be pre-determined, and ReDim Preserve is not used.
good point. i tried to keep the array in some way and show that you can use both good together. i sure should have mentioned it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.