Dans un script , j'ai une fonction qui test la présence de trois fichiers différents .
Seulement, si le fichier choisi n'éxiste pas , autoit me retourne une erreur que je ne sais pas gérer.
'Array variable subscript badly formatted.'
► Afficher le texte
Func _getMot($difficulte)
Local $file = 0
Local $nbr_mots
If $difficulte = 1 Then
$file = FileOpen("dico1", 0)
$nbr_mots = _FileCountLines("dico1")
ElseIf $difficulte = 2 Then
$file = FileOpen("dico2", 0)
$nbr_mots = _FileCountLines("dico2")
ElseIf $difficulte = 3 Then
$file = FileOpen("dico3", 0)
$nbr_mots = _FileCountLines("dico3")
EndIf
local $pos_mot = Random(1, $nbr_mots, 1)
local $mot = FileReadLine($file, $pos_mot)
FileClose($file)
return $mot
EndFunc
Merci de votre aide
Modifié en dernier par pierrotm777 le mar. 23 nov. 2010 12:42, modifié 1 fois.
If FileExists("C:\autoexec.bat") Then
MsgBox(4096, "C:\autoexec.bat File", "Exists") ; votre fonction
Else
MsgBox(4096,"C:\autoexec.bat File", "Does NOT exists") ; un message indiquant que le fichier n'est pas présent
EndIf
Func _getMot($difficulte)
Local $file = 0
Local $nbr_mots
$nom = "dico" & $difficulte ;~ & ".ext"
$file = FileOpen($nom)
If $file = -1 Then
MsgBox(0, "Erreur", "Fichier inexistant ou illisible")
;~ SetError(1) pour gérer les erreurs si tu veux
Return ;~ Return plus approprié qu'un exit je pense
EndIf
$nbr_mots = _FileCountLines($nom)
Local $pos_mot = Random(1, $nbr_mots[color=#FF0000][0][/color], 1)
Local $mot = FileReadLine($file, $pos_mot)
FileClose($file)
Return $mot
EndFunc ;==>_getMot
Il faut mettre [0] pour l'array !
Le "je ne sais pas" et "j'y arrive pas" n'existe dans mon vocabulaire. Toutes Questions ont une réponse, cherchez et vous la trouverai. Utilisez Recherche du forum et vous verrez. Si [blink]Aucune[/blink] question ne tient à votre problème, créez un sujet.
Func _getMot($difficulte)
Dim $nbr_mots
If Not _FileReadToArray("dico" & $difficulte ,$nbr_mots) Then
MsgBox(0, "Erreur", "Fichier inexistant ou illisible")
;~ SetError(1) pour gérer les erreurs si tu veux
Return ;~ Return plus approprié qu'un exit je pense
EndIf
Return $nbr_mots[Random(1, $nbr_mots[0], 1)]
EndFunc ;==>_getMot