|
-
Sep 13th, 2009, 09:39 PM
#1
Thread Starter
New Member
Bubble Sort not working
Hi, I'm a newbie vb6 user and am wondering why my bubble sorting is not working. Please check and see if what's wrong.
I have five text boxes with control array 0 to 4 and I can't get them to display in ascending order. The code below seem to have no effect or just duplicate some numbers.
Code:
Private Sub Command2_Click()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim temp As Integer
flag = 1
Do While flag = 1 And i < 3
flag = 0
i = i + 1
For j = 1 To 4 - i
If txtResult(j + 1) < txtResult(j) Then
temp = txtResult(j)
txtResult(j) = txtResult(j + 1)
txtResult(j + 1) = temp
flag = 1
End If
Next j
Loop
End Sub
Thanks
-
Sep 13th, 2009, 11:29 PM
#2
Re: Bubble Sort not working
The And i < 3 looks like it's not helping the cause.
You can find a standard bubblesort linked in my signature.
-
Sep 14th, 2009, 01:42 AM
#3
Thread Starter
New Member
Re: Bubble Sort not working
Code:
Private Sub Command2_Click()
BubbleSort1 txtResult(i)
End Sub
I tried calling it, but nothing happened. Do I lack something?
-
Sep 14th, 2009, 09:32 PM
#4
Re: Bubble Sort not working
The function is expecting a native array, not an object array, so it won't know what to do with a control array. Store the textbox values to a native array first, sort them, then write the sorted array items back out to the textboxes.
EDIT: By "native array" I mean an array of longs or strings or whatever.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|