把生成的数据排序

来源:百度知道 编辑:UC知道 时间:2024/06/04 11:32:41
在list中,数据的格式是id|名字|名次|人名|
有50多项。怎么把这个list中的数据按名次用VB来排序呢

private type items
id as string
name as string
num as integer
pname as string
end type

private sub command1_click()
dim items() as items, p() as string
dim i as integer
redim preserve items(list1.listcount-1)
for i = 0 to list1.listcount-1
p = split(list1.list(i),"|")
with items(i)
.id = p(0)
.name = p(1)
.num = p(2)
.pname = p(3)
end with
next i

'开始排序
dim j as integer,tmp as items
for i = 0 to ubound(items)-1
for j = 0 to ubound(items)-1
if items(j+1).num<items(j).num then '小的在后面则换位置
with items(j)
tmp.id = .id
tmp.name = .name
tmp.num = .num
tmp.pname = .pname '三角交换开始
end with
with items(j+1)
items(j).id = .id
items(j).name = .name
items(j).num = .num
items(j).pname = .pname
.id = tmp.id
.name = tmp.name
.num = tmp.num
.pname = tmp.pname
end with