Bonjour à tous,
J'ai une erreur :
Erreur d'exécution '13':
Incompatibilite de type
dans la ligne :
Tmp = Split(TextLine, ",")
Et si je commente la ligne :
Dim Tmp()
J'ai une erreur de compilation:
Incompatibilité de type: tableau ou type défini par l'utilisateur attendu
dans la ligne :
TXT = TXT & Concat(Tmp)
Sub ModifTexte()
Dim TXT As String
Dim TextLine As String
Dim Jr As Long, Hr As Long
Dim Tmp()
Filename = ThisWorkbook.Path & "\Jobs.txt"
' Fichier "Jobs.txt"
'TRANSMIT , WAITING, 1, "", 20171110, 1030, 20171110, 1030, 20171116, 1025, 1, 0, immediately, 1, "(1).txt", 1, 0, "Job #1", 0
'TRANSMIT , WAITING, 1, "", 20171110, 1115, 20171110, 1115, 20171116, 1110, 1, 0, immediately, 1, "(2).txt", 1, 0, "Job #2", 0
'TRANSMIT , WAITING, 1, "", 20171111, 0200, 20171111, 0200, 20171117, 0155, 1, 0, immediately, 1, "(3).txt", 1, 0, "Job #3", 0
Open Filename For Input As #1 'Ouverture du fichier en lecture.
Do While Not EOF(1)
Line Input #1, TextLine 'Lecture de la ligne
Tmp = Split(TextLine, ",")
If IsArray(Tmp) Then
MsgBox UBound(Tmp)
Jr = Day(Date)
Hr = Hour([I1])
If Hr >= 0 And Hr <= 9 Then
Jr = Jr + 1
End If
Tmp(4) = Year(Date) & Month(Date) & Jr ' 20171116
Tmp(5) = Format(Hour(Time), "##") & Format(Minute(Time), "00") ' 1500
Tmp(6) = Year(Date) & Month(Date) & Jr ' 20171117
Tmp(7) = Format(Hour(Time), "##") & Format(Minute(Time), "00") ' 1500
Tmp(8) = Year(Date) & Month(Date) & Jr ' 20171116
Tmp(9) = Format(Hour(Time), "##") & Format(Minute(Time) - 5, "00") ' 1655
Debug.Print UBound(Tmp)
Tp = Tmp
TXT = TXT & Concat(Tmp)
[I1] = [I1] + [F1]
End If
Loop
Close #1
Open Filename For Output As #1 'Ouverture du fichier en écriture.
Write #1, TXT 'Je stock dans mon fichier la variable TXT
Close #1
End Sub
Function Concat(Tb() As Variant) As String
Dim i As Long
For i = LBound(Tb) To UBound(Tb)
Concat = Concat + Tb(i) & ","
'Enleve la virgule et ajout d'un retour à la ligne
If i = UBound(Tb) Then Concat = Left(Concat, Len(Concat) - 1) & vbCrLf
Next
End Function
Merci d'avance.