Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array problem

Status
Not open for further replies.

FranckM

Programmer
May 8, 2002
76
CA
Trying to sort in alphabetical order, the date I get from the txt file I have to use I tryed this. I get the same results as before(not in alphabetical order, but in the order that it is found in the file. Here's the code:




function DisplayLinks()

Dim objFS 'File System Object
Dim objFile 'File Object
Dim Name
Dim Link
Dim Desc
Dim Contact
Dim strTxtFile
Dim strLine
Dim nameArray(7)
Dim y

y = 0

IF language_type = "FR" then
strTxtFile = "textfileInFrench.txt"
else
strTxtFile = "textfileInEnglish.txt"
end if

Set objFS = CreateObject("Scripting.FileSystemObject")

If not objFS.FileExists(Server.MapPath(strTxtFile)) then
response.write "File Not Found"

Else

Set objFile = objFS.OpenTextFile(Server.MapPath(strTxtFile), 1, false)

Do Until (objFile.AtEndOfStream)

strLine = objFile.readline
GetValue(strLine)
name = GetValue(strLine)
nameArray(y) = name
y = y + 1

strLine = objFile.readline
strLine = objFile.readline
strLine = objFile.readline
strLine = objFile.readline

strLine = objFile.readline
Loop

objFile.close

Dim bob, i, z
Dim totalElements
i = 0
z = 0
totalElements = 7

for i = 0 to (totalElements - 1)
for z = 1 to totalElements
If nameArray(i) > nameArray(z) then
bob = nameArray(i)
nameArray(i) = nameArray(z)
nameArray(z) = bob
z = z + 1
end if
next
i = i + 1
next

for i = 0 to totalElements
response.write &quot;<ul><li><a href =&quot;&quot;#&quot; & nameArray(i) & &quot;&quot;&quot;>&quot; & nameArray(i) & &quot;</a></ul>&quot;
next

End if
 
I'm getting closer using this has a test:

Dim nameArray(2)
Dim bob, i, z
dim totalElements
i = 0
z = 0
totalElements = 2

nameArray(0) = 3
nameArray(1) = 1
nameArray(2) = 2

for i = i to (totalElements - 1)
for z = (1+i) to totalElements
If nameArray(i) > nameArray(z) then
bob = nameArray(i)
nameArray(i) = nameArray(z)
nameArray(z) = bob
z = z + 1
end if
next
i = i + 1
next

The contents of the array does change to this:
nameArray(0) = 1
nameArray(1) = 3
nameArray(2) = 2

I don't know why it dosen't work for the 2.

Thanks for reading and giving ideas, if any of them pass by.
 
Thank you soooo much, I had to take out the i = i +1 too.

Muchos gracias JohnYingling!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top