Public Function ReadLine(Filename As String, Ln As Integer, ByRef Result As String) As Boolean 'Returns FALSE if the target line was found, otherwise TRUE. 'Renvoit FALSE si la ligne a été trouvée, sinon TRUE. Dim FID As Long: FID = FreeFile Dim i As Integer, CurLine As String Open Filename For Input As FID While EOF(FID) = False i = i + 1 Line Input #FID, CurLine If Ln = i Then Result = CurLine Exit Function End If Wend Close FID ReadLine = True End Function
et je préfère dans un private subApprends le VB et on verra après pour tes préférences .
Dim taVariable As String taVariable = ReadLine("nomDuFichier.xyz",1) 'lit la ligne 1 du fichier nomDuFichier.xyz
ReadLine("nomDuFichier.xyz",1,taVariable)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim Result As String If ReadLine("tonFichier.xyz", 1, Result) = True Then MsgBox "Impossible de lire le fichier ...", vbExclamation Exit Sub '(ou) Exit Function End If Debug.Print "ligne: " & Result