09-12-12, 01:25 AM
تفضل يا غالي
بالتوفيق
كود :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Code As String = ""
Dim N1, N2 As Integer
10:
N1 = RandomInteger(0, 21)
N2 = RandomInteger(0, 21)
Do While N1 = N2
N2 = RandomInteger(0, 21)
Loop
TextBox1.Text = N1 & "|" & N2
If Not RepeatedRandomCount(TextBox1.Text) > 1 Then
ListView1.Items.Add(TextBox1.Text)
ListView1.Items.Add(TextBox1.Text)
Else
GoTo 10 'إذا كان الرقم مكرر مرتين سيبحث عن رقم عشوائي جديد
End If
End Sub
Private Function RandomInteger(ByVal Lowerbound As Integer, ByVal Upperbound As Integer) As Integer
Dim Rnd As New Random
RandomInteger = Rnd.Next(Lowerbound, Upperbound)
End Function
Private Function RepeatedRandomCount(ByVal RandomNumber As String) As Integer
Dim Count As Integer = 0
For Each Item As ListViewItem In ListView1.Items
If Item.Text = RandomNumber Then
Count += 1
End If
Next
Return Count
End Function
