每个VB.net随机数字以不同的标签
我有这个函数返回随机数字,而不用重复的同一个标签除以“,”。 我如何将所有6个值返回到6个不同的标签?
Public Class Tester
Public ds As New DataSet
Public strSQL As String
Public cmd As New MySqlCommand
Public dr As MySqlDataReader
Dim intNumber As Integer
Dim arrNumber(0 To 5) As Integer
Dim i, x, y As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = ""
For x = 0 To 5
Start:
Randomize()
intNumber = Int((49 * Rnd()) + 1)
For y = 0 To 5
If intNumber = arrNumber(y) Then
GoTo Start
End If
Next y
arrNumber(x) = intNumber
Next x
For i = 0 To 5
Label1.Text = (arrNumber(i))
Next
End Sub
End Class
Dim arrNumber(0 To 5) As Integer
'Create the array from your labels:
Dim aLabels() As Label = {Label1, Label2, Label3, Label4, Label5, Label6}
在你的循环中
For i = 0 To 5
aLabels(i).Text = (arrNumber(i))
Next
链接地址: http://www.djcxy.com/p/52793.html
