Page 1 sur 1

[R] Func pas très correct (RandomLettre)

Posté : ven. 16 avr. 2010 14:21
par alex1205
Bonjour, travaillant plusieurs jours pour mettre au point une func qui ne marche pas. :(
La fonction de RandomLettre
Code de la fonction:

Code : Tout sélectionner

Func RandomLettre ($minimal, $maximal) ;$minimal et $maximal doit etre le nombre qui represente la lettre (A=1, B=2, C=3 ...)
    $lettre=Random ($minimal, $maximal, 1)
    If $lettre = "1"  Then
        RandomLettre = "a"
    ElseIf $lettre = "2"  Then
        RandomLettre = "b"
    ElseIf $lettre = "3" Then
        RandomLettre = "c"  
    ElseIf $lettre = "4"  Then
        RandomLettre = "d"  
    ElseIf $lettre = "5" Then
        RandomLettre = "e"
    ElseIf $lettre = "6" Then
        RandomLettre = "f"
    ElseIf $lettre = "7" Then
        RandomLettre = "g"  
    ElseIf $lettre = "8" Then
        RandomLettre = "h"  
    ElseIf $lettre = "9" Then
        RandomLettre = "i"  
    ElseIf $lettre = "10" Then
        RandomLettre = "j"  
    ElseIf $lettre = "11 Then
        RandomLettre = "k"  
    ElseIf $lettre = "12" Then
        RandomLettre = "l"  
    ElseIf $lettre = "13 Then
        RandomLettre = "m"  
    ElseIf $lettre = "14" Then
        RandomLettre = "n"  
    ElseIf $lettre = "15" Then
        RandomLettre = "o"  
    ElseIf $lettre = "16" Then
        RandomLettre = "p"  
    ElseIf $lettre = "17" Then
        RandomLettre = "q"  
    ElseIf $lettre = "18" Then
        RandomLettre = "r" 
    ElseIf $lettre = "19" Then
        RandomLettre = "s"  
    ElseIf $lettre = "20" Then
        RandomLettre = "t"  
    ElseIf $lettre = "21" Then
        RandomLettre = "u"  
    ElseIf $lettre = "22" Then
        RandomLettre = "v"  
    ElseIf $lettre = "23" Then
        RandomLettre = "w"  
    ElseIf $lettre = "24" Then
        RandomLettre = "x"  
    ElseIf $lettre = "25" Then
        RandomLettre = "y"  
    ElseIf $lettre = "26" Then
        RandomLettre = "z"      
    EndIf
EndFunc
 
Merci à l'avance
Alex1205

Re: [..] Func pas très correct (RandomLettre

Posté : ven. 16 avr. 2010 14:37
par GMib
Essaye ceci :

Code : Tout sélectionner

$RandomLettre = RandomLettre("a","z")
MsgBox(0, '', $RandomLettre)

Func RandomLettre ($minimal, $maximal)
  $lettre=Chr(Random (Asc($minimal), Asc($maximal), 1))
  Return $lettre
EndFunc