vb编程,生成N组22选5的彩票号码组(每组有不同的5个数字组成,且每个数码只能取1~22之间的数)在文本框1中输入N值,按运行按钮在列表框中显示结果程序中要定义一个通用过程,用于生成一组
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/23 21:30:12
vb编程,生成N组22选5的彩票号码组(每组有不同的5个数字组成,且每个数码只能取1~22之间的数)在文本框1中输入N值,按运行按钮在列表框中显示结果程序中要定义一个通用过程,用于生成一组
vb编程,生成N组22选5的彩票号码组(每组有不同的5个数字组成,且每个数码只能取1~22之间的数)
在文本框1中输入N值,按运行按钮在列表框中显示结果
程序中要定义一个通用过程,用于生成一组彩票号码.
vb编程,生成N组22选5的彩票号码组(每组有不同的5个数字组成,且每个数码只能取1~22之间的数)在文本框1中输入N值,按运行按钮在列表框中显示结果程序中要定义一个通用过程,用于生成一组
text1 输入n;text2 输出结果
Text2的MultiLine 属性设为True,ScrollBars属性为2
Dim n As Integer,i As Integer,j As Integer,k As Integer
Dim haoma As String
Dim tc22(4) As String
Dim t22(4) As Integer
Dim tp As Integer
Dim ii As String
Private Sub Command1_Click()
haoma = ""
n = Text1.Text
For i = 1 To n
Randomize
t22(0) = Int(Rnd() * 22 + 1)
Do
t22(1) = Int(Rnd() * 22 + 1)
Loop While t22(1) = t22(0)
Do
t22(2) = Int(Rnd() * 22 + 1)
Loop While t22(2) = t22(0) Or t22(2) = t22(1)
Do
t22(3) = Int(Rnd() * 22 + 1)
Loop While t22(3) = t22(0) Or t22(3) = t22(1) Or t22(3) = t22(2)
Do
t22(4) = Int(Rnd() * 22 + 1)
Loop While t22(4) = t22(0) Or t22(4) = t22(1) Or t22(4) = t22(2) Or t22(4) = t22(3)
For j = 0 To 3
For k = j + 1 To 4
If t22(j) > t22(k) Then
tp = t22(j)
t22(j) = t22(k)
t22(k) = tp
End If
Next k,j
For j = 0 To 4
If Len(CStr(t22(j))) = 1 Then
tc22(j) = "0" & CStr(t22(j))
Else
tc22(j) = CStr(t22(j))
End If
If j = 0 Then
If Len(CStr(i)) = 1 Then
ii = "0" & CStr(i)
Else
ii = CStr(i)
End If
haoma = haoma & "No." & ii & ":" & tc22(j) & " "
Else
haoma = haoma & tc22(j) & " "
End If
Next j
If i Mod 5 = 0 Then
haoma = haoma & vbCrLf & vbCrLf
Else
haoma = haoma & vbCrLf
End If
Next i
Text2.Text = haoma
End Sub