Code : Tout sélectionner
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $PFile = "Liste des prénoms 2004-2012.csv"
If Not FileExists($PFile) Then
    MsgBox(16, "Erreur", "Le fichier des prénoms n'a pas été trouvé. Fin du programme.")
    Exit
EndIf
Global $aFPrenoms = FileReadToArray($PFile)
Global $aListePrenoms[UBound($aFPrenoms)][2]
$aListePrenoms[0][0] = UBound($aFPrenoms)
Global $Timeout = 10
; On met en Tableau en ne gardant que le sexe et le prenom.
For $i = 1 To UBound($aFPrenoms) - 1
    $aInfos = StringSplit($aFPrenoms[$i], ";")
    $aListePrenoms[$i][0] = $aInfos[3]
    $aListePrenoms[$i][1] = $aInfos[1]
Next
GUICreate("", 308, 186, -1, -1)
Global $Genre1 = GUICtrlCreateRadio("Masculin", 24, 64, 73, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
Global $Genre2 = GUICtrlCreateRadio("Féminin", 24, 96, 73, 17)
Global $CMin = GUICtrlCreateCombo("2", 136, 88, 41, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "2|3|4|5|6|7|8|9")
Global $CMax = GUICtrlCreateCombo("20", 224, 88, 41, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20")
GUICtrlCreateLabel("Longueur Mini", 120, 64, 71, 17)
GUICtrlCreateLabel("Longueur Maxi", 208, 64, 74, 17)
GUICtrlCreateLabel("Choix d'un prénom :", 72, 8, 162, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
Global $Go = GUICtrlCreateButton("Go", 72, 152, 75, 25)
Global $Annuler = GUICtrlCreateButton("Annuler", 160, 152, 75, 25)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Annuler
            Exit
        Case $Go
            Local $Genre = "", $Min = 2, $Max = 20, $Choix = "", $ListChoix = ""
            ; On récupère le genre souhaité
            If BitAND(GUICtrlRead($Genre1), $GUI_CHECKED) = $GUI_CHECKED Then
                $Genre = "M"
            Else
                $Genre = "F"
            EndIf
            ; On récupère les valeurs Min et Max
            $Min = GUICtrlRead($CMin)
            $Max = GUICtrlRead($CMax)
            Local $Timer = TimerInit() ; Timer pour règler la durée du timeout de traitement
            While 1
                $Choix = Random(1, UBound($aListePrenoms) - 1, 1)
                If StringInStr($ListChoix, $Choix) Then ContinueLoop ; Pour éviter de reprendre le même choix
                $ListChoix &= "|" & $Choix
                Local $PLong = StringLen($aListePrenoms[$Choix][1])
                If StringInStr($aListePrenoms[$Choix][0], $Genre) Then
                    If $PLong >= $Min  And $PLong <= $Max  Then
                        MsgBox(64, "Prénom", "Prénom choisit : " & $aListePrenoms[$Choix][1] & @TAB)
                        ExitLoop
                    EndIf
                EndIf
                ; Test du TimeOut
                If Int(TimerDiff($Timer)/1000) > $Timeout Then
                    MsgBox(16, "Erreur", "Timeout de traitement atteind. Veuillez recommencer avec des critères moins restrictifs.")
                    ConsoleWrite($ListChoix & @CRLF)
                    ContinueCase
                EndIf
            WEnd
    EndSwitch
WEnd