注册 登录
编程论坛 VB.NET论坛

(已经解决)请教各位高手,vb.net(vs2010)用字典方法统计重复数据如何实现?谢谢。

HVB6 发布于 2017-07-04 17:47, 1756 次点击
dim a() As Integer = {11, 22, 11, 11, 8, 9, 6, 8, 9}
(vs2010)的字典方法统计以上数组的重复和不重复数据以及其重复和不重复的次数。
VBA和vb6.0的个例很多,但(vs2010)不见一列。以上的算法请不要用任何控件,即象
VBA和vb6.0一样用纯的代码实现。谢谢。

[此贴子已经被作者于2017-7-4 23:29编辑过]

1 回复
#2
HVB62017-07-04 23:28
已经解决,在窗体里画个命令按钮,双击命令按钮,把以下代码粘贴→调试→启动调试→点击命令按钮,ok.
Public Class Form1
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer = 0, s As String = ""
        Dim a() As Integer = {11, 22, 11, 11, 8, 9, 6, 8, 9}
        Dim d = CreateObject("Scripting.Dictionary")
        For i = LBound(a) To UBound(a)
            d(a(i)) = d(a(i)) + 1
        Next
        Dim arr = d.keys
        Dim brr = d.items
        ' MsgBox(brr(0))
        ' MsgBox(d.count)
        For i = 0 To d.count - 1
            s = s & arr(i) & "   个数   " & brr(i) & Chr(10)
        Next
        MsgBox(s)
    End Sub
End Class
1