Ποτέ δεν έχω βάλει κάτι προγραμματιστικό και μια και έπαιζα με κάτι ρουτίνες θα βάλω τη μία από τις δύο λύσεις στο πρόβλημα που δημιούργησα για να παίξω...
Είναι η λάθος λύση προφανώς αλλά μου αρέσουν οι πίνακες.
Η σωστή είναι πιο απλή και μικρότερη... αλλά τούτη εδώ έχει ένα ενδιαφέρον για το Exit For
Enjoy...
Public Class Form1
Dim rndNumber As New Random()
Dim arNumbers(44) As Integer
Dim arTzoker(19) As Integer
Dim arSelected(4) As Integer
Dim i As Integer = 0
Dim numbers As Integer = 1
Dim swExit As Boolean = False
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
If numbers > 5 Then
i = rndNumber.Next(0, arTzoker.Length - 1)
lblTzoker.Text = (i + 1).ToString
btnStart.Enabled = False
btnReload.Enabled = True
Else
lblNumb.Text = lblNumb.Text & numbers & vbCrLf
getNumbers()
numbers = numbers + 1
End If
End Sub
Private Sub getNumbers()
If numbers = 1 Then
i = rndNumber.Next(0, arNumbers.Length - 1)
arSelected(numbers - 1) = i + 1
lblNumbers.Text = i + 1
Exit Sub
End If
i = rndNumber.Next(0, arNumbers.Length - 1)
For idx = 0 To numbers - 1
If arSelected(idx) = (i + 1) Then
lblDouble.Text = lblDouble.Text & (i + 1).ToString() & vbCrLf
getNumbers()
swExit = True
Exit For
End If
Next
If swExit = False Then
arSelected(numbers - 1) = i + 1
lblNumbers.Text = ""
For idx As Integer = 0 To numbers - 1
lblNumbers.Text = lblNumbers.Text & arSelected(idx) & vbCrLf
Next
Else
swExit = False
End If
'lblNumbers.Text = lblNumbers.Text + (i + 1).ToString + Environment.NewLine
Exit Sub
End Sub
Private Sub btnReload_Click(sender As Object, e As EventArgs) Handles btnReload.Click
Init()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Init()
End Sub
Private Sub Init()
For idx = 0 To arNumbers.Length - 1
arNumbers(idx) = idx + 1
Next
For idx = 0 To arTzoker.Length - 1
arTzoker(idx) = idx + 1
Next
btnReload.Enabled = False
btnStart.Enabled = True
numbers = 1
i = 0
For idx = 0 To 4
arSelected(idx) = 0
Next
lblTzoker.Text = ""
lblDouble.Text = ""
lblNumbers.Text = ""
lblNumb.Text = ""
End Sub
Private Sub btnForm2_Click(sender As Object, e As EventArgs) Handles btnForm2.Click
Me.Hide()
Form2.Show()
End Sub
End Class
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου