Member Avatar for westsiderailway

Hi eveyone,

I have a few labels in a panel and found this bit of code...

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim RndGen As New Random
              For Each ctrl As Control In Panel1.Controls
                           Dim lbl As Label = TryCast(ctrl, Label)
                If lbl IsNot Nothing Then
                    lbl.Text = RndGen.Next(1, 45).ToString
                End If


        Next

    End Sub

what i would like to do is , put the text values into an array. So that i can evaluate them to see if any are equal to each other.
if 2 are both the same, then lose both . The idea is to end up with random single number all different.

 Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim RndGen As New Random
        Dim lblarray(21) As String

        For Each ctrl As Control In Panel1.Controls
            For P As Integer = 0 To 21
                Dim lbl As Label = TryCast(ctrl, Label)
                If lbl IsNot Nothing Then
                    lbl.Text = RndGen.Next(1, 45).ToString
                End If

                lblarray(P) = lbl.Text
            Next
        Next

    End Sub

I have done the above code, but it is not quite working out...

Many thanks for reading.

Member Avatar for westsiderailway

ok Folks solved part of the problem....:-)

 Dim RndGen As New Random
        Dim lblarray(21) As String
        Dim P As Integer = 0

        For Each ctrl As Control In Panel1.Controls

            Dim lbl As Label = TryCast(ctrl, Label)
            If lbl IsNot Nothing Then
                lbl.Text = RndGen.Next(1, 45).ToString
                lblarray(P) = lbl.Text
            End If
            P = P + 1

        Next

THis put the label.text into the array, now all i have to figure out is how to compare then to each other.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.