点击command1在list中生成n组数据,n在文本框中显示,每组数据是“红球”六个1~33的随机数“篮球”一个1~
点击command1在list中生成n组数据,n在文本框中显示,每组数据是“红球”六个1~33的随机数“篮球”一个1~16的随机数组成,以下是答案,为什么运行不出来呢?是...
点击command1在list中生成n组数据,n在文本框中显示,每组数据是“红球”六个1~33的随机数“篮球”一个1~16的随机数组成,以下是答案,为什么运行不出来呢?是需要该什么属性吗
Private Sub Command1_Click()
Dim a(7) As Integer, n As Integer
Dim i As Integer
List1.Clear
n = Val(Text1.Text)
For i = 1 To n
Call fun(a)
For j = 1 To 6
s = s & "" & a(j)
Next j
List1.AddItem "红球" & s & "" & "篮球" & a(7)
s = ""
Erase a
Next i
End Sub
Sub fun(a() As Integer)
Dim i As Integer, x As Integer
Do While i <= 6
x = Int(Rnd * 33) + 1
For j = 1 To 6
If x = a(j) Then Exit For
nextj
If j > 6 Then
i = i + 1
a(i) = x
End If
Loop
a(7) = Int(Rnd * 16) + 1
End Sub 展开
Private Sub Command1_Click()
Dim a(7) As Integer, n As Integer
Dim i As Integer
List1.Clear
n = Val(Text1.Text)
For i = 1 To n
Call fun(a)
For j = 1 To 6
s = s & "" & a(j)
Next j
List1.AddItem "红球" & s & "" & "篮球" & a(7)
s = ""
Erase a
Next i
End Sub
Sub fun(a() As Integer)
Dim i As Integer, x As Integer
Do While i <= 6
x = Int(Rnd * 33) + 1
For j = 1 To 6
If x = a(j) Then Exit For
nextj
If j > 6 Then
i = i + 1
a(i) = x
End If
Loop
a(7) = Int(Rnd * 16) + 1
End Sub 展开
1个回答
展开全部
1、如果你是复制的源代码,那么这个代码里面有错误。其中,
“nextj”应该是“next j”。
“s = s & "" & a(j)”应该是“s = s & " " & a(j)”
2、运行的时候,应当先在文本框中输入相应的数据。如果文本框中没有数据,那么就会从“For i = 1 To n”中退出来,不会循环处理数据。
3、如果在List1.AddItem "红球" & s & "" & "篮球" & a(7)改为List1.AddItem "红球 " & s & " " & "篮球 " & a(7),那么就正确了。
修改以后的完整代码如下:
Option Explicit
Private Sub Command1_Click()
Dim a(7) As Integer, n As Integer
Dim i As Integer, j As Integer
Dim s As String
List1.Clear
n = Val(Text1.Text)
For i = 1 To n
Call fun(a)
For j = 1 To 6
s = s & " " & a(j)
Next j
List1.AddItem "红球 " & s & " " & "篮球 " & a(7)
s = ""
Erase a
Next i
End Sub
Sub fun(a() As Integer)
Dim i As Integer, x As Integer
Dim j As Integer
Do While i <= 6
x = Int(Rnd * 33) + 1
For j = 1 To 6
If x = a(j) Then Exit For
Next
If j > 6 Then
i = i + 1
a(i) = x
End If
Loop
a(7) = Int(Rnd * 16) + 1
End Sub
“nextj”应该是“next j”。
“s = s & "" & a(j)”应该是“s = s & " " & a(j)”
2、运行的时候,应当先在文本框中输入相应的数据。如果文本框中没有数据,那么就会从“For i = 1 To n”中退出来,不会循环处理数据。
3、如果在List1.AddItem "红球" & s & "" & "篮球" & a(7)改为List1.AddItem "红球 " & s & " " & "篮球 " & a(7),那么就正确了。
修改以后的完整代码如下:
Option Explicit
Private Sub Command1_Click()
Dim a(7) As Integer, n As Integer
Dim i As Integer, j As Integer
Dim s As String
List1.Clear
n = Val(Text1.Text)
For i = 1 To n
Call fun(a)
For j = 1 To 6
s = s & " " & a(j)
Next j
List1.AddItem "红球 " & s & " " & "篮球 " & a(7)
s = ""
Erase a
Next i
End Sub
Sub fun(a() As Integer)
Dim i As Integer, x As Integer
Dim j As Integer
Do While i <= 6
x = Int(Rnd * 33) + 1
For j = 1 To 6
If x = a(j) Then Exit For
Next
If j > 6 Then
i = i + 1
a(i) = x
End If
Loop
a(7) = Int(Rnd * 16) + 1
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询