<%@ LANGUAGE = VBScript %> Commanders Promotion Procedure: Top 20 Commanders
Click here for the 'Window on' Series Index Click here for the BNSC Click here for the PPARC Click here for the Sunday Times
Click here for WOU Home
Mission to Mars Simulation:
Top Twenty Commanders

<% Const ForReading = 1, ForWriting = 2, ForAppending = 8 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 ' OPEN THE FILE Set FileObject = Server.CreateObject("Scripting.FileSystemObject") ScoresFile = Server.MapPath("/") + "\wou\mtm\scores.txt" ' BUILD STRUCTURES FOR SORTING Dim dObj, aTemp Set dObj = Server.CreateObject("Scripting.Dictionary") ' READ THE FILE INFORMATION Set ScoresStream = FileObject.GetFile(ScoresFile) Set ReadStream = ScoresStream.OpenAsTextStream(ForReading, TristateUseDefault) Do While ReadStream.AtEndOfStream <> True line = ReadStream.ReadLine comma1 = InStr(line, "#") comma2 = InStr(comma1+1, line, "#") If Not ((comma1 < 1) Or (comma2 < 1)) Then name = Mid(line, 1, comma1-1) score = Mid(line, comma1+1, comma2-comma1-1) level = Mid(line, comma2+1) If Not dObj.Exists(CStr((CLng(score)+1000000000000000)) & level & name) Then dObj.Add CStr((CLng(score)+1000000000000000)) & level & name, "" + vbnewline End If End If Loop ReadStream.Close ' WRITE OUT THE VALUES Call PrintSortedDictionary(dObj) Set dObj = Nothing Sub BuildArray(objDict, aTempArray) Dim nCount, strKey nCount = 0 '-- Redim the array to the number of keys we need Redim aTempArray(objDict.Count - 1) '-- Load the array For Each strKey In objDict.Keys '-- Set the array element to the key aTempArray(nCount) = strKey '-- Increment the count nCount = nCount + 1 Next End Sub Sub SortArray(aTempArray) Dim iTemp, jTemp, strTemp For iTemp = 0 To UBound(aTempArray) For jTemp = 0 To iTemp If strComp(aTempArray(jTemp),aTempArray(iTemp)) < 0 Then 'Swap the array positions strTemp = aTempArray(jTemp) aTempArray(jTemp) = aTempArray(iTemp) aTempArray(iTemp) = strTemp End If Next Next End Sub Sub PrintDictionary(objDict, aTempArray) Dim iTemp For iTemp = 0 To UBound(aTempArray) If iTemp < 20 Then Response.Write(objDict.Item(aTempArray(iTemp))) End If Next End Sub Sub PrintSortedDictionary(objDict) Dim aTemp Call BuildArray(objDict, aTemp) ' Build the array Call SortArray(aTemp) ' Sort the array Call PrintDictionary(objDict, aTemp) ' Print the dictionary using the array as an index End Sub %>
CommanderFunds SavedDays Taken
" + name + " " + FormatNumber(score, 0, 0, 0, -1) + " Credits" + level + "

 

You will need to play MTM to register your score here.
Get your free WOU CDROM Set from BNSC.