Dim Capture As Boolean Dim Ligne As String Dim Temp As String Capture = False Open "c:\test.txt" For Input As #1 'le fichier txt Do While Not EOF(1) Line Input #1, Ligne If InStr(LCase(Ligne), LCase("AddOns")) <> 0 Then Capture = True If InStr("};", Ligne) <> 0 Then Exit Do If Capture And Left(Ligne, 1) Chr(34) Then Temp Temp & Ligne Loop 'On supprime les " et on supprime le dernier "," Temp = Replace(Temp, Chr(34), "") Temp = Left(Temp, Len(Temp) - 1) 'Temp contient la classe addons séparé par des ",", pour les recuperer un par un il faut 'faire un split de temp avec separateur "," MsgBox "Variable temp : " & Temp 'Split Dim Mot() As String Mot = Split(Temp, ",") For i = 0 To UBound(Mot) MsgBox "Mot nr" & i & " : " & Mot(i) Next i
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionSub Macro1() Dim i As Integer Dim a$ Dim compte As Integer 'tableau qui contiendra les valeurs trouvées ReDim maVal(1) compte = 0 i = FreeFile Open "c:\test.txt" For Input As #i Do Until EOF(i) Line Input #i, a$ If InStr(1, a$, "addOns[]=") Then Exit Do Loop Line Input #i, a$ Do Until EOF(i) Line Input #i, a$ If InStr(1, a$, "};") Then Exit Do compte = compte + 1 ReDim Preserve maVal(compte) a$ = Trim(a$) If Len(a$) > 1 Then If Right(a$, 1) = "," Then a$ = Left(a$, Len(a$) - 1) End If a$ = Replace(a$, Chr(34), " ") maVal(compte) = Trim(a$) End If Loop Close #i End Sub
Sub Macro1() Dim i As Integer Dim a$ Dim compte As Integer Dim az As Integer 'tableau qui contiendra les valeurs trouvées ReDim maVal(1) compte = 0 i = FreeFile Open (App.Path & "" & "mat.txt") For Input As #i Do Until EOF(i) Line Input #i, a$ If InStr(1, a$, "addOns[]=") Then Exit Do Loop Line Input #i, a$ Do Until EOF(i) Line Input #i, a$ If InStr(1, a$, "};") Then Exit Do compte = compte + 1 ReDim Preserve maVal(compte) a$ = Trim(a$) If Len(a$) > 1 Then If Right(a$, 1) = "," Then a$ = Left(a$, Len(a$) - 1) End If a$ = Replace(a$, Chr(34), "") az = i For az = 1 To compte a$ = Right(a$, Len(a$) - 1) Next az maVal(compte) = Trim(a$) End If Loop Close #i Kill (App.Path & "" & "mat.txt") MsgBox "Valeurs : " & maVal(1) & Chr$(10) & " || Valeur 2 : " & maVal(2) End Sub
a$ = Replace(a$, vbTab, " ")