Bonjour , j'ai écris un bout de code permettant de générer un code à 5 caractères distincts avec des lettres de l'alphabet allant de "a à i" et 4 symboles : + * / = ( il marche mais j'estime qu'on peut faire surement mieux)
, il y a t il un moyen de le faire plus court par exemple ..merci .
Sub gen_code_5_chif_dist()
t = Array("a", "b", "c", "d", "e", "f", "g", "h", "i")
x = t(Int(Rnd * 9))
' MsgBox x
For i = 0 To UBound(t)
If t(i) = x Then
y = y & x
t(i) = Replace(t(i), x, "*")
'on reboucle dans le nouveau tableau obtenu
'*******************************
x = t(Int(Rnd * 9))
' MsgBox x
For j = 0 To UBound(t)
If t(j) = x Then
y = y & x
t(j) = Replace(t(j), x, "/")
'on reboucle encor une 3 ieme fois :
'********************************************
x = t(Int(Rnd * 9))
'MsgBox x
For k = 0 To UBound(t)
If t(k) = x Then
y = y & x
t(k) = Replace(t(k), x, "+")
'on rebloucle une 4 ieme fois
'*******************************************
x = t(Int(Rnd * 9))
'MsgBox x
For s = 0 To UBound(t)
If t(s) = x Then
y = y & x
t(s) = Replace(t(s), x, "-")
'*****************************************
'on reboucle une 5 ieme fois
x = t(Int(Rnd * 9))
'MsgBox x
For w = 0 To UBound(t)
If t(w) = x Then
y = y & x
t(w) = Replace(t(w), x, "=")
End If
Next
'******************************************
End If
Next
'*******************************************
End If
Next
'********************************************
End If
Next
'********************************
End If
Next
MsgBox y
End Sub