macro not working with all txt files

SBAY3I

Board Regular
Joined
Jul 21, 2018
Messages
53
VBA Code:
Sub lirebenzing(nf)
    With Sheets("résultats")
        k = .Cells(Rows.Count, 1).End(xlUp).Row
        Open nf For Input As 1
        Do
            Line Input #1, v
            If v <> "" Then
                q = Mid(v, 3, 7)
                If q = "BENZING" Then
                    q = Mid(v, 57, 19)
                    de$ = Trim(Replace(Replace(Replace(q, ".", "/"), "-", " "), "|", ""))
                    nr = 0
                    sr = 0
                Else
                    q = Left(v, 7)
                    If q = "Amateur" Then
                        propn = Mid(v, 56)
                        propn = Trim(propn)
                        propid = Mid(v, 17, 12)
                        xp = 0
                        yp = 0
                        setxyp propn, propid, xp, yp
                    Else
                        s = InStr(v, "Lieu de lacher")
                        If s <> 0 Then
                            s1 = InStr(v, ":")
                            lieuid = Mid(v, s1 + 1, s - s1 - 2)
                            lieun = Mid(v, s + 15)
                            lieun = Trim(lieun)
                        ElseIf lieuid <> "" And (Left(v, 3) = "No." Or Left(v, 3) = "Ord") Then
                            nr = 1
                        ElseIf Left(v, 3) = "---" Or Left(v, 3) = "+--" Then
                            If nr = 1 Then sr = 1
                        ElseIf Left(v, 3) = "+--" Or InStr(v, "Signatur") <> 0 Then
                            nr = 0
                            sr = 0
                        ElseIf sr = 1 Then
                            If Not dp Then
                                k = k + 1
                                .Cells(k, 1) = course
                                .Cells(k, 2) = datecourse
                                .Cells(k, 3) = "'" & propid
                                .Cells(k, 4) = propn
                                t = Split(v, "|")
                                .Cells(k, 5) = t(0)
                                .Cells(k, 5) = Val(.Cells(k, 5))
                                .Cells(k, 6) = "'" & t(6)
                                t1 = Split(suppresp(t(1)), " ")
                                .Cells(k, 7) = "'" & t1(1)
                                .Cells(k, 8) = "'" & t1(2)
                                .Cells(k, 9) = "'" & t1(3)
                                j = 4
                                While t1(j) = ""
                                    j = j + 1
                                Wend
                                .Cells(k, 10) = "'" & t1(j)
                                .Cells(k, 11) = "'" & t(2)
                                .Cells(k, 12) = "'" & t(3)
                                If Left(t(4), 6) <> "pas ar" Then
                                    .Cells(k, 13) = "'" & Left(t(4), 3)
                                    .Cells(k, 14) = TimeValue(Mid(t(4), 6))
                                End If
                                .Cells(k, 16) = idcourse
                                .Cells(k, 17) = de
                                .Cells(k, 18) = "BENZING"
                                .Cells(k, 19) = nf
                                .Cells(k, 20) = x
                                .Cells(k, 21) = y
                                .Cells(k, 22) = xp
                                .Cells(k, 23) = yp
                                .Cells(k, 24) = Sqr((xp - x) ^ 2 + (yp - y) ^ 2)
                                If Val(.Cells(k, 5)) <> 0 Then
                                    .Cells(k, 25) = .Cells(k, 14) - (datecourse - Int(datecourse))
                                    .Cells(k, 26) = .Cells(k, 24) * 1000 / (.Cells(k, 25) * 24 * 60)
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        Loop While Not EOF(1)
        Close
    End With
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
can you add such a TXT-file or are there sensitive data in in ?
Does it work with CSV-files or not at all ?
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: macro reading txt file but not with other
and macro reading txt file but not with other
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
VBA Code:
Sub lirebenzing(nf)
    With Sheets("résultats")
        k = .Cells(Rows.Count, 1).End(xlUp).Row
        Open nf For Input As 1
        Do
            Line Input #1, v
            If v <> "" Then
                q = Mid(v, 3, 7)
                If q = "BENZING" Then
                    q = Mid(v, 57, 19)
                    de$ = Trim(Replace(Replace(Replace(q, ".", "/"), "-", " "), "|", ""))
                    nr = 0
                    sr = 0
                Else
                    q = Left(v, 7)
                    If q = "Amateur" Then
                        propn = Mid(v, 56)
                        propn = Trim(propn)
                        propid = Mid(v, 17, 12)
                        xp = 0
                        yp = 0
                        setxyp propn, propid, xp, yp
                    Else
                        s = InStr(v, "Lieu de lacher")
                        If s <> 0 Then
                            s1 = InStr(v, ":")
                            lieuid = Mid(v, s1 + 1, s - s1 - 2)
                            lieun = Mid(v, s + 15)
                            lieun = Trim(lieun)
                        ElseIf lieuid <> "" And (Left(v, 3) = "No." Or Left(v, 3) = "Ord") Then
                            nr = 1
                        ElseIf Left(v, 3) = "---" Or Left(v, 3) = "+--" Then
                            If nr = 1 Then sr = 1
                        ElseIf Left(v, 3) = "+--" Or InStr(v, "Signatur") <> 0 Then
                            nr = 0
                            sr = 0
                        ElseIf sr = 1 Then
                            If Not dp Then
                                k = k + 1
                                .Cells(k, 1) = course
                                .Cells(k, 2) = datecourse
                                .Cells(k, 3) = "'" & propid
                                .Cells(k, 4) = propn
                                t = Split(v, "|")
                                .Cells(k, 5) = t(0)
                                .Cells(k, 5) = Val(.Cells(k, 5))
                                .Cells(k, 6) = "'" & t(6)
                                t1 = Split(suppresp(t(1)), " ")
                                .Cells(k, 7) = "'" & t1(1)
                                .Cells(k, 8) = "'" & t1(2)
                                .Cells(k, 9) = "'" & t1(3)
                                j = 4
                                While t1(j) = ""
                                    j = j + 1
                                Wend
                                .Cells(k, 10) = "'" & t1(j)
                                .Cells(k, 11) = "'" & t(2)
                                .Cells(k, 12) = "'" & t(3)
                                If Left(t(4), 6) <> "pas ar" Then
                                    .Cells(k, 13) = "'" & Left(t(4), 3)
                                    .Cells(k, 14) = TimeValue(Mid(t(4), 6))
                                End If
                                .Cells(k, 16) = idcourse
                                .Cells(k, 17) = de
                                .Cells(k, 18) = "BENZING"
                                .Cells(k, 19) = nf
                                .Cells(k, 20) = x
                                .Cells(k, 21) = y
                                .Cells(k, 22) = xp
                                .Cells(k, 23) = yp
                                .Cells(k, 24) = Sqr((xp - x) ^ 2 + (yp - y) ^ 2)
                                If Val(.Cells(k, 5)) <> 0 Then
                                    .Cells(k, 25) = .Cells(k, 14) - (datecourse - Int(datecourse))
                                    .Cells(k, 26) = .Cells(k, 24) * 1000 / (.Cells(k, 25) * 24 * 60)
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        Loop While Not EOF(1)
        Close
    End With
End Sub

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: macro reading txt file but not with other
and macro reading txt file but not with other
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
hi
i dont put the link of other forum to avoide breaking the rules of mrexcel.com that's why
 
Upvote 0
il manque un espace.
your 2 txt files are different, the program suppose that there are 4 arguments in the 2nd split of a line.
There is a missing space between those 5 or 6 digits and that "F" or "M" (the sexe i suppose).
The macro can be modified, but it's perhaps better to ask why the textfile is modified.
 

Attachments

  • Schermafbeelding 2022-04-10 064441.png
    Schermafbeelding 2022-04-10 064441.png
    14.7 KB · Views: 8
  • Schermafbeelding 2022-04-10 064544.png
    Schermafbeelding 2022-04-10 064544.png
    15.1 KB · Views: 8
Upvote 0
Even with a modification of the macro, i think there are too much differences between both textfiles to solve the problem.
Are all variables in the 2nd non-ok textfile present ?
 

Attachments

  • Schermafbeelding 2022-04-10 071113.png
    Schermafbeelding 2022-04-10 071113.png
    25 KB · Views: 8
Upvote 0
i dont put the link of other forum to avoide breaking the rules of mrexcel.com that's why
The rules clearly state that you must provide links to all other sites where you have cross posted, so I don't understand what you are saying.
 
Upvote 0
il manque un espace.
your 2 txt files are different, the program suppose that there are 4 arguments in the 2nd split of a line.
There is a missing space between those 5 or 6 digits and that "F" or "M" (the sexe i suppose).
The macro can be modified, but it's perhaps better to ask why the textfile is modified.
hi
they are différent because the source not the same, yes one company but différent smart pigeons clock , thats why
i want to attached the workbook but i couldnt
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top