发布网友 发布时间:2024-10-24 02:36
共2个回答
热心网友 时间:2024-11-01 00:33
参考一下下面的代码!
Private Type UserInfo '定义一个UserInfo 自定义类型
name As String * 6 '姓名
result As Integer '成绩
End Type
Private Sub Form_Load()
Show
Dim a(5) As UserInfo '定义一个UserInfo类型的5个元素的数组
Dim t As UserInfo
'初始化**************
a(1).name = "小王": a(1).result = 65
a(2).name = "小张": a(2).result = 70
a(3).name = "小李": a(3).result = 80
a(4).name = "张三": a(4).result = 60
a(5).name = "王四": a(5).result = 61
'以上的部分用户可以自己输入
'下面开始排序*************************
For i = 1 To 4
For j = 1 To 5 - i
If a(j).result < a(j + 1).result Then
t.result = a(j).result
a(j).result = a(j + 1).result
a(j + 1).result = t.result
t.name = a(j).name
a(j).name = a(j + 1).name
a(j + 1).name = t.name
End If
Next j
Next i
For i = 1 To 5
Print a(i).result; a(i).name
Next
End Sub
热心网友 时间:2024-11-01 00:36
举例说明吧,假设成绩放在A(1 to 10),姓名放在B(1 to 10),用下列代码可以(从大到小排列):
dim I as integer,J as integer,temp
for i=1 to 9
for j=i+1 to 10
if a(i)<a(j) then
temp=a(i):a(i)=a(j):a(j)=temp
temp=b(i):b(i)=a(j):b(j)=temp
end if
next j
next i