Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'==========================================================================
'
' NAME: sort.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: http://www.thespidersparlor.com
' DATE : 2/10/2004
'
' COMMENT: Reads a file into an array, sorts it and writes the data back to the file.
'
'==========================================================================
Option Explicit
Dim oFSO, ForReading, ForWriting, sortFile, MyList, myArray, ts, i, j, temp, line, report
ForReading = 1
ForWriting = 2
Set oFSO=CreateObject("Scripting.FileSystemObject")
[b][i]'comment out the next line if you want to supress prompting for the file location[/i][/b]
sortFile = InputBox("What file should I sort? Full path please!", "File To Sort")
[b][i]'uncomment the next line if you want to have a static file location[/i][/b]
'sortFile = "C:\Test.log"
MyList= ofso.OpenTextFile(sortFile, ForReading).ReadAll
myArray=Split(MyList,vbCrLf, -1, vbtextcompare)
[i][b]'bubble sort thanks to Richard Lowe, 4GuysFromRolla.com [/b]
'what he does here is check each element in the array
'against the next value to see if it is greater than it.
'If location1 is > location2 write location1 to temp,
'then write location2 to location1 and finally write
'temp to location2[/i]
for i = UBound(myArray) - 1 To 0 Step -1
for j= 0 to i
if myArray(j)>myArray(j+1) then
temp=myArray(j+1)
myArray(j+1)=myArray(j)
myArray(j)=temp
end if
next
next
[i]'end bubble sort. Thanks Richard![/i]
For Each line In myArray
[b][i] 'Check for blank lines and ignore them[/i][/b]
If Len(line) <> 0 Then
report = report & line & vbcrlf
End If
Next
MsgBox "The following will be written to " & sortfile & vbCrLf & report, vbOkOnly
[b][i]'Now write the data back to the original file in sorted order[/i][/b]
Set ts = oFSO.CreateTextFile (sortFile, ForWriting)
ts.write report