Vb6 如何对数组排序

Vb6 如何对数组排序,vb6,Vb6,使用VB6.0,我有一个包含“English”字段的学校数据库,我使用SQL创建了一个记录集,并按描述顺序排列了英语。我的问题是,我想对这些学生进行排名,以便在平局后,下一个学生在平局计数后获得排名,如下所示: 英语:45,48,67,67,67,80,80,91 英语等级 91 - 1 80 - 2 80 - 2, 67 - 4, 67 - 4, 67 - 4, 48 - 7, 45-8,你的问题不太清楚,但我

使用VB6.0,我有一个包含“English”字段的学校数据库,我使用SQL创建了一个记录集,并按描述顺序排列了英语。我的问题是,我想对这些学生进行排名,以便在平局后,下一个学生在平局计数后获得排名,如下所示:

英语:45,48,67,67,67,80,80,91

英语等级 91 - 1 80 - 2 80 - 2, 67 - 4, 67 - 4, 67 - 4, 48 - 7,
45-8,

你的问题不太清楚,但我想你想要这样的东西

select Eng, rank() over (order by Eng desc) EnglishRank from somewhere

我猜你的意思与下面的代码大致相同。我只是用一种方法从程序中获取数据。你可能会做一些不同的事情

Option Explicit

Private Type RankedScores
    Rank                As Long
    Score               As Long
End Type

Private Sub RankValues(ByRef the_rs As ADODB.Recordset, ByRef out_auRankedScores() As RankedScores)

    Dim nIndex                                  As Long
    Dim nRank                                   As Long
    Dim nScore                                  As Long
    Dim nLastScore                              As Long

    nRank = 0
    nIndex = 0

    ' Resize the output buffer to its maximum size (won't work on some types of recordsets).
    ReDim out_auRankedScores(1 To the_rs.RecordCount)

    Do Until the_rs.EOF

        nIndex = nIndex + 1

        ' Pull score out of the recordset. If it is not the same as the last score, then increment the rank.
        nScore = CLng(the_rs.Fields.Item("English"))
        If nScore <> nLastScore Then
            nRank = nIndex
        End If

        ' Write into output buffer.
        With out_auRankedScores(nIndex)
            .Rank = nRank
            .Score = nScore
        End With

        ' Reset last score.
        nLastScore = nScore

        ' Next row.
        the_rs.MoveNext
    Loop

End Sub
选项显式
私有类型RankedScores
排名一样长
得分一样长
端型
私有子rankvalue(ByRef作为ADODB.Recordset,ByRef out作为RankedScores())
暗九倍长
暗淡无光
暗芯与长芯一样
我的分数和你的一样长
nRank=0
nIndex=0
'将输出缓冲区调整为其最大大小(在某些类型的记录集上不起作用)。
重拨出\u auRankedScores(1到\u rs.RecordCount)
直到最后一刻
nIndex=nIndex+1
'将分数从记录集中拉出。如果与上一个分数不相同,则增加排名。
nScore=CLng(字段项(“英语”))
如果nScore NLAST得分,则
nRank=nIndex
如果结束
'写入输出缓冲区。
不含auRankedScores(nIndex)
.Rank=nRank
.Score=nScore
以
“重置最后的分数。
nLastScore=nScore
“下一排。
下一步行动
环
端接头

如果您向我们展示您迄今为止编写的代码,我们会更轻松。请注意,不是全部,而是重要的部分。告诉我们你有多远。阿桑特。