怎么用vb随机生成1~10000的10000个数,在按1~1000 1001~2000 2001~3000 9001~1

1个回答

  • '在窗体上画两个列表框(ListBox),一个按钮(CommandButton)

    '粘贴以下代码

    '单击List1里的范围,在List2里列出该分类的所有数据

    Dim Num(1 To 10000) As Integer

    Private Sub Command1_Click()

    List1.Clear

    List2.Clear

    On Error Resume Next

    For i = 1 To 10000

    Randomize

    Num(i) = Int(10000 * Rnd)

    Next

    For i = 0 To 9

    List1.AddItem i * 1000 + 1 & " & (i + 1) * 1000

    Next

    For i = 1 To 10000

    If Num(i) >= 1 And Num(i) = List1.ListIndex * 1000 + 1 And Num(i)