This is a pretty tough one in my opinion...

I have 4 parallel arrays, each increasing as lines are being read from a text file. The four arrays are booktitle, retail value, books on hand, and books on order. I have to find a way to sort all four arrays in ALPHABETICAL ORDER BY TITLE. So, for example, if the second element of the booktitle array was AAA, then that element AS WELL AS THE OTHER ARRAYS CORRESPONDING TO THAT ARRAY (AAA's retail value, AAA's on hand, AAA'S on order) need to be shifted to the first element position. I HAVE to use four parallel arrays so I cannot change that. Any ideas?

Here's the code:

Private Sub mnuItemOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuItemOpen.Click
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

            myInFile = File.OpenText(OpenFileDialog1.FileName)
            If File.Exists(OpenFileDialog1.FileName) Then
                Do Until myInFile.Peek = -1
                    ReDim Preserve bookTitleArray(bookTitleCounter)
                    bookTitleArray(bookTitleCounter) = myInFile.ReadLine()
                    bookTitleCounter += 1
                    ReDim Preserve retailValueArray(retailValueCounter)
                    retailValueArray(retailValueCounter) = myInFile.ReadLine()
                    retailValueCounter += 1
                    ReDim Preserve booksHandArray(booksHandCounter)
                    booksHandArray(booksHandCounter) = myInFile.ReadLine()
                    booksHandCounter += 1
                    ReDim Preserve booksOrderArray(booksOrderCounter)
                    booksOrderArray(booksOrderCounter) = myInFile.ReadLine()
                    booksOrderCounter += 1
                Loop
            End If
        Else
            MessageBox.Show("File does not exist.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

maybe not the best solution but a working one...

Dim arr1() As String = {"BAX", "XDS", "AAA", "GFD", "AAB"}
		Dim arr2() As String = {"67", "45", "2", "88", "89"}
		Dim arr3() As String = {"b4", "g5", "j3", "k8", "d3"}
		Dim arr4() As String = {"df", "hj", "tz", "we", "xs"}

		Dim count As Integer = arr1.GetUpperBound(0)
		
		Console.WriteLine("Original:")

		For x As Integer = 0 To count
			Console.WriteLine(String.Format("{0} - {1} - {2} - {3}", arr1(x), arr2(x), arr3(x), arr4(x)))
		Next x

		Dim arrkey(count) As String			  'hold original array
		Dim arrkey2(count) As String		  'hold original array
		Array.Copy(arr1, arrkey, count + 1)
		Array.Copy(arr1, arrkey2, count + 1)

		Array.Sort(arr1, arr2, 0, count + 1)
		Array.Sort(arrkey, arr3, 0, count + 1)
		Array.Sort(arrkey2, arr4, 0, count + 1)
		Console.WriteLine("Sorted:")

		For x As Integer = 0 To count
			Console.WriteLine(String.Format("{0} - {1} - {2} - {3}", arr1(x), arr2(x), arr3(x), arr4(x)))
		Next x
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.