假设有自定义类型studentPublic Type Student    
记录号 As Integer
姓名 As String * 10
总分 As Single
End Type声明变量stu
Public stu() As Student重定义数组为stu(1 to recnum)其中变量stu有recnum条记录,
记录号 姓名  总分
1       ding  78
2      tong   67
3      bobo   98
4      yoyo   88
5       ling   79请大家帮忙如何用冒泡法将总分降序排列显示在图片框picture1上?

解决方案 »

  1.   


    Option Base 1
    Private Type Student
        No As Integer
        Name As String * 10
        Score As Single
    End TypeDim stu() As Student
    Dim i As IntegerPrivate Sub Form_Load()
        Picture1.AutoRedraw = True
        ReDim stu(5)
        
        For i = 1 To 5
            stu(i).No = i
        Next i    stu(1).Name = ding
        stu(1).Score = 78
       
        stu(2).Name = tong
        stu(2).Score = 67
        
        stu(3).Name = bobo
        stu(3).Score = 98
      
        stu(4).Name = yoyo
        stu(4).Score = 88    stu(5).Name = ling
        stu(5).Score = 79
    End Sub
    Private Sub Command1_Click()
        Dim t As Student
        Dim j As Integer
        For i = 1 To UBound(stu) - 1
            For j = 1 To UBound(stu) - i
               If stu(j).Score < stu(j + 1).Score Then
                   t = stu(j + 1)
                   stu(j + 1) = stu(j)
                   stu(j) = t
               End If
            Next j
        Next i
        For i = 1 To UBound(stu)
            Picture1.Print stu(i).Score
        Next i
    End Sub