Jag skriver ner en massa ord i en textfil, ett ord per rad.
När jag sedan läser in detta, och visar i en textarea, så skulle jag vilja ha det sorterat.
Jag hämtar textfilen:
Function HamtaText
Const Filename = "../Styles/arraytest.asp"
Filepath = Server.MapPath(Filename)
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
strFilePath = Filepath 'Server.Mappath( "\" ) & "\undermapp\filen.asp"
set objFile = objFso.OpenTextFile( strFilePath, 1 )
arrFsoLines = Split( objFile.ReadAll, vbcrlf )
for i = 0 to ubound( arrFsoLines )
Response.Write arrFsoLines( i ) & vbcrlf
next
objFile.Close
Set objFile = Nothing
Set objFso = Nothing
...som jag kallar på via
<%
Response.Write HamtaText
%>
Sen har jag hittat ett litet script för sortering:
function arraysort(values())
Dim i
Dim j
Dim smallest_value
Dim smallest_j
dim min,max
dim m
dim temp
on error resume next
min = lbound(values,2)
max = ubound(values,2)
For i = min To max
smallest_value = values(0,i)
smallest_j = i
For j = i + 1 To max
' See if values(j) is smaller. changed to strComp to work with strings.
'If strComp(values(0,j),smallest_value,vbTextCompare) = -1 Then
If cdbl(values(0,j)) < cdbl(smallest_value) and Len(values(0,j))<> 0 Then
' Save the new smallest value.
smallest_value = values(0,j)
smallest_j = j
End If
Next 'j
If smallest_j <> i Then
' Swap items i and smallest_j.
for intA = 0 to ubound(values,1)
temp = values(intA,smallest_j)
values(intA,smallest_j) = values(intA,i)
values(intA,i) = temp
next 'intA
End If
Next 'i
arraysort = values
End function
Vad jag förstår så måste jag koppla den någonstans, och hur jag än försöker blir det fel...
Och error:
Error Number=9
Error Descr.=Felaktigt matrisindex
Help Context=0
Source=Körningsfel i Microsoft VBScript
och du pekar den på lbound och ubound.
Hur löser jag detta(går det)?