VB随机数为一个数组,但不知道怎么定义数组下标如下面的代码:Private Sub Command1_Click()b = InputBox("输入随机数的个数-1")Dim a()Randomize:Text1 = ""For i = 0 To ba(i) = Int(Rnd * 5 + 1)For j = 0 To iIf i j And a(i) = a(
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/29 00:07:07
VB随机数为一个数组,但不知道怎么定义数组下标如下面的代码:Private Sub Command1_Click()b = InputBox("输入随机数的个数-1")Dim a()Randomize:Text1 = ""For i = 0 To ba(i) = Int(Rnd * 5 + 1)For j = 0 To iIf i j And a(i) = a(
VB随机数为一个数组,但不知道怎么定义数组下标
如下面的代码:
Private Sub Command1_Click()
b = InputBox("输入随机数的个数-1")
Dim a()
Randomize:Text1 = ""
For i = 0 To b
a(i) = Int(Rnd * 5 + 1)
For j = 0 To i
If i j And a(i) = a(j) Then i = i - 1:Exit For
Next j,i
For i = 0 To 4
Text1 = Text1 & a(i) & " "
Next
End Sub
如运行,会出现下标越界,如把dim a() 写成 dim a (b)又要求常数表达示,写成dim a (uboun(a)) 也不行,只有手动写成4````````郁闷,我要求是inputbox时让b=4就这么简单,怎么就不行呢?请指教一下,要怎么定义这个a的下标啊?
4只是假如,可能输入321````怎么弄啊````
VB随机数为一个数组,但不知道怎么定义数组下标如下面的代码:Private Sub Command1_Click()b = InputBox("输入随机数的个数-1")Dim a()Randomize:Text1 = ""For i = 0 To ba(i) = Int(Rnd * 5 + 1)For j = 0 To iIf i j And a(i) = a(
Private Sub Command1_Click()
Dim i%, j%, b%, a%() '定义变量
b = InputBox("输入随机数的个数-1")
If b < 1 Then Exit Sub
ReDim a(b) '注意,用redim
Randomize: Text1 = ""
For i = 0 To b
a(i) = Int(Rnd * (b + 1) + 1) '太小会死循环的噢.
For j = 0 To i
If i j And a(i) = a(j) Then i = i - 1: Exit For '使用排序可能更合适!数字大了会很慢的,不建议使用剔除法!
Next j, i
For i = 0 To b
Text1 = Text1 & a(i) & " "
Next
End Sub