我有这个函数,它返回随机数而不会在同一标签中重复除以“,”。如何将所有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
答案 0 :(得分:0)
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