Private m As Integer, n As Integer
Private Sub Command1_Click()
If IsNumeric(Text1) = False Then '位数保护
MsgBox "位数必须输入数字"
Text1.SetFocus
Else
If Val(Trim(Text1)) < 1 Or Val(Trim(Text1)) > 4 Then
MsgBox "位数是1~4的正整数"
Text1 = ""
Text1.SetFocus
End If
End If
If IsNumeric(Text2) = False Then '个数保护
MsgBox "个数必须输入数字"
Text2.SetFocus
Else
If Val(Trim(Text2)) < 1 Or Val(Trim(Text2)) > 100 Then
MsgBox "个数是1~100的正整数"
Text2 = ""
Text2.SetFocus
End If
End If
Text3 = ""
Dim i As Integer, k As Integer
m = Val(Trim(Text1))
n = Val(Trim(Text2))
For i = 1 To n '产生n个随机数
Randomize
Select Case m '区别位数
Case 1
k = 1 + Int(Rnd * 9)
Case 2
k = 10 + Int(Rnd * 90)
Case 3
k = 100 + Int(Rnd * 900)
Case 4
k = 1000 + Int(Rnd * 9000)
End Select
Text3 = Text3 & k & "," '填充
文本框
Next i
End Sub