龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VB开发 >

按字母或数字顺序排列列表框中的列表项

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
将以下代码加入到你的程序中。 Sub ReSort(L As Control) Dim P%, PP%, C%, Pre$, S$, V, NewPos%, CheckIt% Dim TempL$, TempItemData, S1$ For P = 0 To L.ListCount - 1 S = L.List(P) For C = 1 To Len(S) V = Val(Mid$(S, C)) If V 0 Then

将以下代码加入到你的程序中。
Sub ReSort(L As Control)
Dim P%, PP%, C%, Pre$, S$, V&, NewPos%, CheckIt%


Dim TempL$, TempItemData&, S1$
For P = 0 To L.ListCount - 1
S = L.List(P)
For C = 1 To Len(S)
V = Val(Mid$(S, C))
If V > 0 Then Exit For
Next
If V > 0 Then
If C > 1 Then Pre = Left$(S, C - 1)
NewPos = -1
For PP = P + 1 To L.ListCount - 1
CheckIt = False
S1 = L.List(PP)
If Pre <> "" Then
If InStr(S1, Pre) = 1 Then CheckIt = True
Else
If Val(S1) > 0 Then CheckIt = True
End If
If CheckIt Then
If Val(Mid$(S1, C)) < V Then NewPos = PP
Else
Exit For
End If
Next
If NewPos > -1 Then
TempL = L.List(P)
TempItemData = L.ItemData(P)
L.RemoveItem (P)
L.AddItem TempL, NewPos
L.ItemData(L.NewIndex) = TempItemData
P = P - 1
End If
End If
Next
Exit Sub

精彩图集

赞助商链接