VB.net随机编号各自到不同的标签

VB.net random numbers each to different label

我有一个函数,它返回随机数,不重复相同的标签除以","。如何将所有6个值返回到6个不同的标签?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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

1
2
3
Dim arrNumber(0 To 5) As Integer
'Create the array from your labels:
Dim aLabels() As Label = {Label1, Label2, Label3, Label4, Label5, Label6}

在你的环 P / < >

1
2
3
For i = 0 To 5
    aLabels(i).Text = (arrNumber(i))
Next