In my effort to understand Do-Loops, I've written the following code. The form has two arrays txtInput and lblOutput. The objective is to have the user input five numbers and have code arrange the numbers in ascending order and display them in the output label array. I must be missing something because the only output I'm getting is the lowest number in the output array. Can anyone help?
Here's my code.......
Option Explicit
Dim TopIndex As Integer
Dim OtherTopIndex As Integer
Dim NextItem As Integer
Dim LoopCount As Integer
Private Sub cmdArrange_Click()
NextItem = 0
Do While NextItem < 4
TopIndex = 4
Do While TopIndex > NextItem
If Val(txtInput(TopIndex)) < Val(txtInput(TopIndex - 1)) Then
lblOutput(OtherTopIndex) = Val(txtInput(TopIndex))
Else: lblOutput(OtherTopIndex) = Val(txtInput(TopIndex - 1))
End If
TopIndex = TopIndex - 1
Loop
NextItem = NextItem + 1
Loop
End Sub
Here's my code.......
Option Explicit
Dim TopIndex As Integer
Dim OtherTopIndex As Integer
Dim NextItem As Integer
Dim LoopCount As Integer
Private Sub cmdArrange_Click()
NextItem = 0
Do While NextItem < 4
TopIndex = 4
Do While TopIndex > NextItem
If Val(txtInput(TopIndex)) < Val(txtInput(TopIndex - 1)) Then
lblOutput(OtherTopIndex) = Val(txtInput(TopIndex))
Else: lblOutput(OtherTopIndex) = Val(txtInput(TopIndex - 1))
End If
TopIndex = TopIndex - 1
Loop
NextItem = NextItem + 1
Loop
End Sub