|
-
Nov 27th, 2000, 10:11 PM
#1
Thread Starter
New Member
I'm trying to get the sorted list of 10 numbers to show up in txtSorted, but it's not happening. What am I doing wrong?
Code:
Private Sub cmdSort_Click()
For pos = 1 To 9
min = intArray(pos)
minInd = pos
For index = pos + 1 To 8
If intArray(index) < min Then
min = intArray(index)
minInd = index
End If
Next index
temp = intArray(pos)
intArray(pos) = intArray(index)
intArray(index) = temp
txtSorted.Text = intArray(pos) & " " & txtSorted.Text
Next pos
txtSorted.Text = intArray(10) & " " & txtSorted.Text
End Sub
-
Nov 28th, 2000, 02:36 AM
#2
Addicted Member
Try this:
Code:
--------------------------------------------------
Option Explicit
Dim intArray(9) As Integer
Dim pos As Integer
Dim index As Integer
Dim min As Integer
Dim intTemp As Integer
Private Sub cmdSort_Click()
For pos = 0 To 8
min = intArray(pos)
For index = pos + 1 To 9
If intArray(index) < min Then
intTemp = intArray(index)
intArray(index) = min
min = intTemp
End If
Next index
intArray(pos) = min
Next pos
For pos = 0 To 9
txtSorted.Text = txtSorted.Text & intArray(pos) & " "
Next pos
End Sub
------------------------------------------------
Hope it helps.
-
Nov 28th, 2000, 08:36 AM
#3
_______
<?>
or this way...
Code:
Private Sub Form_Load()
Dim i As Integer
Randomize
Dim myArr(9)
For i = 0 To 9
myArr(i) = Fix(Rnd * 22)
Next i
Call mySort(myArr)
Text1.Text = ""
For i = LBound(myArr) To UBound(myArr)
Text1 = Text1 & myArr(i) & vbNewLine
Next i
End Sub
Sub mySort(iArray As Variant)
Dim lLoop1 As Long
Dim lLoop2 As Long
Dim lTemp As Long
For lLoop1 = UBound(iArray) To LBound(iArray) Step -1
For lLoop2 = LBound(iArray) + 1 To lLoop1
If iArray(lLoop2 - 1) > iArray(lLoop2) Then
lTemp = iArray(lLoop2 - 1)
iArray(lLoop2 - 1) = iArray(lLoop2)
iArray(lLoop2) = lTemp
End If
Next lLoop2
Next lLoop1
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 28th, 2000, 09:30 AM
#4
Addicted Member
HeSaidJoe's code is versatile. Well done.
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
|