codice:
Public Class frmMain
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
Timer1.Start()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Timer1.Stop()
Timer1.Enabled = False
Timer2.Stop()
Timer2.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
lblA.Text = GenKey.rndLetters(1)
lblB.Text = GenKey.rndLetters(1)
lblC.Text = GenKey.rndLetters(1)
lblD.Text = GenKey.rndLetters(1)
lblE.Text = GenKey.rndLetters(1)
lblF.Text = GenKey.rndLetters(1)
lblG.Text = GenKey.rndLetters(1)
lblH.Text = GenKey.rndLetters(1)
lblI.Text = GenKey.rndLetters(1)
lblL.Text = GenKey.rndLetters(1)
lblM.Text = GenKey.rndLetters(1)
lblN.Text = GenKey.rndLetters(1)
lblO.Text = GenKey.rndLetters(1)
lblP.Text = GenKey.rndLetters(1)
lblQ.Text = GenKey.rndLetters(1)
lblR.Text = GenKey.rndLetters(1)
lblS.Text = GenKey.rndLetters(1)
lblT.Text = GenKey.rndLetters(1)
lblU.Text = GenKey.rndLetters(1)
lblV.Text = GenKey.rndLetters(1)
lblZ.Text = GenKey.rndLetters(1)
lbl1.Text = GenKey.rndNumber(1)
lbl2.Text = GenKey.rndNumber(1)
lbl3.Text = GenKey.rndNumber(1)
lbl4.Text = GenKey.rndNumber(1)
lbl5.Text = GenKey.rndNumber(1)
lbl6.Text = GenKey.rndNumber(1)
lbl7.Text = GenKey.rndNumber(1)
lbl8.Text = GenKey.rndNumber(1)
lbl9.Text = GenKey.rndNumber(1)
lbl10.Text = GenKey.rndNumber(1)
lbl11.Text = GenKey.rndNumber(1)
lbl12.Text = GenKey.rndNumber(1)
lbl13.Text = GenKey.rndNumber(1)
lbl14.Text = GenKey.rndNumber(1)
lbl15.Text = GenKey.rndNumber(1)
lbl16.Text = GenKey.rndNumber(1)
lbl17.Text = GenKey.rndNumber(1)
lbl18.Text = GenKey.rndNumber(1)
lbl19.Text = GenKey.rndNumber(1)
lbl20.Text = GenKey.rndNumber(1)
lbl21.Text = GenKey.rndNumber(1)
Timer2.Enabled = True
Timer2.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
controlla(lblA.Text)
End Sub
End Class
codice:
Module GenKey
Public Function rndLetters(ByVal length As Integer) As String
Dim sb As New System.Text.StringBuilder
Dim chars() As String = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "L", _
"M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "Z"}
Dim upperBound As Integer = UBound(chars)
For x As Integer = 1 To length
sb.Append(chars(Int(Rnd() * upperBound)))
Next
Return sb.ToString
End Function
Public Function rndNumber(ByVal length As Integer) As String
Dim sb As New System.Text.StringBuilder
Dim chars() As String = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", _
"13", "14", "15", "16", "17", "18", "19", "20", "21"}
Dim upperBound As Integer = UBound(chars)
For x As Integer = 1 To length
sb.Append(chars(Int(Rnd() * upperBound)))
Next
Return sb.ToString
End Function
'funzione che controlla l'array di etichette in funzione del testo generato...
Public Function controlla(ByVal path As String) As Boolean
Dim myArray() As String = {frmMain.lblA.Text, frmMain.lblB.Text, frmMain.lblC.Text, frmMain.lblD.Text, _
frmMain.lblE.Text, frmMain.lblF.Text, frmMain.lblG.Text, frmMain.lblH.Text, frmMain.lblI.Text, _
frmMain.lblL.Text, frmMain.lblM.Text, frmMain.lblN.Text, frmMain.lblO.Text, frmMain.lblP.Text, _
frmMain.lblQ.Text, frmMain.lblR.Text, frmMain.lblS.Text, frmMain.lblT.Text, frmMain.lblU.Text, _
frmMain.lblV.Text, frmMain.lblZ.Text}
For Each path In myArray
If String.Compare(path, myArray.ToString, 0, 2, True) = True Then
Return True
MsgBox(True)
Else
Return False
MsgBox(False)
End If
Next
End Function
End Module
grazie