Question Locked

Vb 2005 - arrays

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Below is a task i have been set to build. I have to build an array of 10 inputs, when you click sort - it sorts the array 1, 3, 7, 12 etc...

Please help

Private Sub btnSort_Click(Index As Integer)
Dim count1 As Integer
Dim count2 As Integer
Dim temp As Integer
Dim xArray(4)
Dim yArray(4)

For count1 = 10 To 1 Step -1
For count2 = 1 To count1
num1 = xArray(count2 - 1)
num2 = yArray(count2)
If num1 < num2 Then
temp = xArray(count2 - 1)
temp1 = xArray(count2 - 1) = xArray(count2)

xArray(count2) = temp
End If
Next count2

Next count1

End Sub

Private Sub Command1_Click(Index As Integer)

Dim myArray(10) As Integer
Dim myCount As Integer
'Dim marked(51) As Integer

If Me.text2 = "" Then
Exit Sub
End If
Me.text2.SetFocus
myArray(myCount) = Me.text2

If Me.Text3 = 4 Then
Exit Sub
Else
Me.Text1 = Me.Text1 & myArray(myCount) & vbCrLf
Me.Text3 = Me.Text3 + 1
Me.text2 = " "
Exit Sub

'

End If

End Sub

Private Sub Form_Activate()
Me.text2.SetFocus
Me.Text3 = 0
End Sub

2 replies

by tony hopkinson

temp1 ???

x an y arrays with dimensions of 4 indexed in a loop from 1 to 10

array of 10 items is a local variable in one method, and you want to sort it in another without passing it or making it a form property they can both refernce.

You need to take a couple of steps back mate, and ffs make sure option explicit is on.

This discussion is closed to new replies.