如何用VB实现数组合排序并删除重复数?
首先将下面五组数分别对应输入据第一组(08 10 16 25 28 33 )第二组(12 13 19 22 28 29 )第三组(01 07 08 20 23 24 )第四组(01 04 20 24 28 29 )第五组(12 20 25 26 27 28 )。然后点击计算按钮后,对这五组数据实现数组合排序并删除重复数。并将结果输入结果文本框。 --------------------编程问答--------------------Sub main()--------------------编程问答-------------------- 利用 VB 控件 ListBox 可以轻松解决。
Dim a(4), b(1 To 33), msg As String
a(0) = Array(8, 10, 16, 25, 28, 33)
a(1) = Array(12, 13, 19, 22, 28, 29)
a(2) = Array(1, 7, 8, 20, 23, 24)
a(3) = Array(1, 4, 20, 24, 28, 29)
a(4) = Array(12, 20, 25, 26, 27, 28)
For i = 0 To 4
For j = 0 To UBound(a(i))
b(a(i)(j)) = 1
Next j, i
For i = 1 To 33
If b(i) Then msg = msg & i & " "
Next
MsgBox msg
End Sub
在窗体上放一个 ListBox,Sorted 属性设置为 True。
Private Declare Function SendMessagebyString Lib _
"user32" Alias "SendMessageA" (ByVal hWND As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String) As Long
Private Const LB_FINDSTRINGEXACT = &H1A2 '在 ListBox 中精确查找
Private Sub Command1_Click()
Dim i As Integer, j As Integer, n As Long
For i = 0 To Ubound(a, 1)
For j = 0 To Ubound(a, 2)
n = SendMessagebyString(List1.hWnd, LB_FINDSTRINGEXACT, -1, a(i, j))
If n = -1 Then List1.AddItem a(i, j)
Next j
Next i
End Sub
补充:VB , 基础类