|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Ordering numbers in arrays.
Can someone tell me how to order a set of numbers. Here's how things are set up:
I want the variable "Player(0, 0)" to contain (in an array) the order of a few numbers. (Player(0, 0) would be the highest, Player(0, 1) would be next, all the way to 10) (I would also do this for Player(1, 1) and so on until 20 actually, and I'm prepared for loading times, but I want it to be as fast as possible... (progressbar is included)) Lets say there were two Players. I have a variable for each, which contains the number to order (lets say PlayerLvl(0, 0) is the variable, and PlayerLvl(1, 0) is the second). Lets say PlayerLvl(0, 1) is the higher one. This how is what Player would contain: Player(0, 0) = 1 'PlayerLvl(1, 0) Player(0, 1) = 0 'PlayerLvl(0, 0) I need a function to assign "Player", in the order greatest to least, the first dimension of PlayerLvl. I hope you understand. All of those 0's and 1's sure do look like binary... Thanks! P.S. (If that doesn't make sense, providing an efficient way to order numbers (I need to order numbers an average of 21 x 50 times while doing this)) I hope to make this loading only around 10 - 20 seconds for 50 people if it's possible (or less would be great actually, I'm not sure how long it'd take!) |
|
#2
|
|||
|
|||
|
ok, I didn't get help fast enough, so I just stored all records into an Access database, and now I can sort
![]() |
|
#3
|
||||
|
||||
|
you can also use something known as "disconnected recordset" and save
yourself the need for database. here is full sample code in vbscript, it can be converted easily to VB: Code:
<% Option Explicit %>
<%
Public arr, x
arr=Array(12,87,44,56,123,543,32,55,95,87)
Call PrintArray(arr)
Call rsSort(arr)
Call PrintArray(arr)
Sub PrintArray(myArr)
Response.Write("<BR><U>Start of array:</U><BR>")
For x=LBound(myArr) To UBound(myArr)
Response.Write("<B>"&x&". "&myArr(x)&"</B><BR>")
Next
Response.Write("<U>End of array</U><BR><BR>")
End Sub
Sub rsSort(ByRef myArr)
Dim rs
Set rs=Server.CreateObject("ADODB.Recordset")
Const adVarChar = 200
Const adInteger = 3
Const adDate = 7
'''rs.Fields.Append "date", adDate
'''rs.Fields.Append "type", adVarChar, 255
rs.Fields.Append "Key", adInteger
rs.Open
For x=0 To UBound(myArr)
rs.AddNew : rs.Fields("Key").Value = myArr(x)
Next
rs.Sort="Key DESC"
rs.MoveFirst
x=0
Do While Not rs.EOF
myArr(x)=rs("Key")
x=x+1
rs.MoveNext
Loop
rs.Close
Set rs=Nothing
End Sub
%>
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Ordering numbers in arrays. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|