Spike
09-11-2000, 07:16 PM
I need to output all the contents of a list box into a text file. (.txt) First, all of the items in the list box are numbers and are in numrical (sp?) order. When the use opens the text file all the numbers need to be in numrical order. like-
1
2
3
11
17
35
125
165
1364
3153
Any suggestions? If you need more info, please post a responce and I will try to explain better. Thanks in advance.
usetheforce2
09-11-2000, 09:40 PM
i suppose the first thing you would want to do is sort the numbers in accending order, judging by you demo.
use a simple bubble sort, with all of the value stored in an array
Dim Temp As Integer
' '------------------ bubble sort in acending fashion
For Cnt = 0 To arraysize
'------------------ cnt compares the varible one time
For Counter = Cnt To arraysize
'------------------ counter loop through the list to locate the lowest number
If Cnt <> Counter Then
'------------------ to ensure the same variable position does not compare itself
If numberarray(Cnt) > numberarray(Counter) Then
'------------------ swap the smaller number
Temp = numberarray(Cnt)
numberarrayCnt) = numberarray(Counter)
numberarray(Counter) = Temp
End If
End If
Next
Next
---------------- or -------------
you could just use the sort property for the listbox,
then save the file, this will save it straight from the list box-----------------------------------
open app.path + "File.txt" for output as #1
for cnt = 0 to list1.listcount - 1
print #1,list1.list(cnt)
next
close #1
if stored in array-----------------------
open app.path + "file.txt" for output as #1
for cnt = 0 to arraysize
print #1, numberarray(cnt)
next
close #1
-------------------------------
good luck, enjoy
Regan