VB.net random numbers each to different label
I have this function which returns random numbers without repeating in same label divided by ",". How can I return all 6 values to 6 different labels?
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/52794.html
上一篇: 修改多个任务使用的实例变量
下一篇: 每个VB.net随机数字以不同的标签