Jump to content

script crash


mailmaster
 Share

Recommended Posts

Trying to make a comparison of two text files ("old" and "new", lines in the files are not in the same order in both files) and extracting into two new files ("bajas" and "novedades") the news lines in one of them and the disapeered lines in the other, i make it with filereadline like this:

$FicheroViejo = FileOpen($NFicheroViejo, 0)

If $FicheroViejo = -1 Then

MsgBox(0, "Error", "Imposible abrir el fichero " & $NFicheroViejo)

Exit

EndIf

$aCodViejo[0]=""

While 1 And Ubound($aCodViejo)<1000

$sLinea = FileReadLine($FicheroViejo)

If @error = -1 Then

ExitLoop

MsgBox(0, "Error leyendo la linea siguiente:", $sLinea)

EndIf

$SeparaenTrozos=StringSplit($sLinea,"|",1)

if $aCodViejo[0]="" then

$aCodViejo[0]=$SeparaenTrozos[5]

Else

_ArrayAdd ( $aCodViejo, $SeparaenTrozos[5] )

EndIf

GUICtrlSetData ( $LFicheroViejo, "Leyendo Viejos: " & String(UBound($aCodViejo)))

If @error = 1 Then

ExitLoop

MsgBox(0, "Linea completa=", $sLinea)

EndIf

Wend

FileClose($FicheroViejo)

etc...

This is very slow (files are about 9000 lines) so I try to do reading the files into memory and then comparing :

$NFicheroViejo=GUICtrlRead ($AIFicheroViejo)

$NFicheroNuevo=GUICtrlRead ($AIFicheroNuevo)

if ($NFicheroViejo="Arrastra aquí el fichero viejo" or $NFicheroNuevo="Arrastra aquí el fichero nuevo") or $NFicheroViejo=$NFicheroNuevo Then

MsgBox(4096, "Atención", "Debes seleccionar fichero Viejo y fichero nuevo antes de procesar", 5)

Else

$aCodViejo[0]=""

If Not _FileReadToArray($NFicheroViejo,$aLineasViejo) Then

MsgBox(4096,"Error", "Error al leer: " &$NFicheroViejo& @error)

Exit

EndIf

For $iCont= 1 to $aLineasViejo[0]

$SeparaenTrozos=StringSplit($aLineasViejo[$iCont],"|",1)

if $aCodViejo[0]="" then

$aCodViejo[0]=$SeparaenTrozos[5]

Else

_ArrayAdd ( $aCodViejo, $SeparaenTrozos[5] )

EndIf

GUICtrlSetData ( $LFicheroViejo, "Leyendo Viejos: " & String(UBound($aCodViejo)))

Next

$aLineasNuevo=0

$aCodNuevo[0]=""

If Not _FileReadToArray($NFicheroNuevo,$aLineasNuevo) Then

MsgBox(4096,"Error", "Error al leer: " &$NFicheroNuevo& @error)

Exit

EndIf

For $iCont= 1 to $aLineasNuevo[0]

$SeparaenTrozos=StringSplit($aLineasNuevo[$iCont],"|",1)

if $aCodNuevo[0]="" then

$aCodNuevo[0]=$SeparaenTrozos[5]

Else

_ArrayAdd ( $aCodNuevo, $SeparaenTrozos[5] )

EndIf

GUICtrlSetData ( $LFicheroNuevo, "Leyendo Nuevos: " & String(UBound($aCodNuevo)))

Next

but this crash at about the record 8500 and i dont know why.

An example of the lines and why I separe it in pieces and make the comparation in the 5th piece of the line:

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|804666|FLUMIL INFANTIL 100MG/SOB 30 SOBRES GRANU SOL ORAL|2.59|

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|800474|ACETILC FARMASIERRA 100MG 30 SOB MON GRA SOL O EFG|2.05|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|730549|ACETILCISTEINA BEXAL 100MG/SOB 30 SOB EFG|2.05|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|851683|ACETILCISTEINA MERCK 100MG GRANUL SOL ORAL 30 EFG|2.05|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|650158|ACETILCISTEINA CINFAMED 100MG 30 SOBRES SOL OR EFG|2.06|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|653992|ACETILCISTEINA ACOST 100MG 30 SOB POLV SUSP OR EFG|1.81|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|653884|ACETILCISTEINA UR 100MG 30 SOBR POLVO SOL ORAL EFG|1.8|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|656241|ACETILCISTEINA NORMON 100MG 30 SOBR GR SO ORAL EFG|1.75|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|650429|ACETILCISTEINA CINFA 100MG 30 SOBRES SOL OR EFG|1.81|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|652631|ACETILCISTEINA ANGENERICO 100MG 30 SOB PO S OR EFG|1.81|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|773366|ACETILCISTEINA SANDOZ 100MG/SOB 30 SOB GRAN OR EFG|2.05|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|788919|ACETILCISTEINA TARBIS 100MG/SOB 30 SOB MONODOS EFG|1.81|EFG

Any ideas to help me?

(I excuse me for my english and the poor explication of the problem.)

Thank you very much

Link to comment
Share on other sites

Sorry but this is how you should post. It's really easier this way:

Trying to make a comparison of two text files ("old" and "new", lines in the files are not in the same order in both files) and extracting into two new files ("bajas" and "novedades") the news lines in one of them and the disapeered lines in the other, i make it with filereadline like this:

$FicheroViejo = FileOpen($NFicheroViejo, 0)
If $FicheroViejo = -1 Then
MsgBox(0, "Error", "Imposible abrir el fichero " & $NFicheroViejo)
Exit
EndIf
$aCodViejo[0]=""
While 1 And Ubound($aCodViejo)<1000
$sLinea = FileReadLine($FicheroViejo)
If @error = -1 Then
ExitLoop
MsgBox(0, "Error leyendo la linea siguiente:", $sLinea)
EndIf
$SeparaenTrozos=StringSplit($sLinea,"|",1)
if $aCodViejo[0]="" then
$aCodViejo[0]=$SeparaenTrozos[5]
Else
_ArrayAdd ( $aCodViejo, $SeparaenTrozos[5] )
EndIf
GUICtrlSetData ( $LFicheroViejo, "Leyendo Viejos: " & String(UBound($aCodViejo)))
If @error = 1 Then
ExitLoop
MsgBox(0, "Linea completa=", $sLinea)
EndIf
Wend
FileClose($FicheroViejo)

etc...

This is very slow (files are about 9000 lines) so I try to do reading the files into memory and then comparing :

$NFicheroViejo=GUICtrlRead ($AIFicheroViejo)
$NFicheroNuevo=GUICtrlRead ($AIFicheroNuevo)
if ($NFicheroViejo="Arrastra aquí el fichero viejo" or $NFicheroNuevo="Arrastra aquí el fichero nuevo") or $NFicheroViejo=$NFicheroNuevo Then
MsgBox(4096, "Atención", "Debes seleccionar fichero Viejo y fichero nuevo antes de procesar", 5)
Else
$aCodViejo[0]=""
If Not _FileReadToArray($NFicheroViejo,$aLineasViejo) Then
MsgBox(4096,"Error", "Error al leer: " &$NFicheroViejo& @error)
Exit
EndIf
For $iCont= 1 to $aLineasViejo[0]
$SeparaenTrozos=StringSplit($aLineasViejo[$iCont],"|",1)
if $aCodViejo[0]="" then
$aCodViejo[0]=$SeparaenTrozos[5]
Else
_ArrayAdd ( $aCodViejo, $SeparaenTrozos[5] )
EndIf
GUICtrlSetData ( $LFicheroViejo, "Leyendo Viejos: " & String(UBound($aCodViejo)))
Next
$aLineasNuevo=0
$aCodNuevo[0]=""
If Not _FileReadToArray($NFicheroNuevo,$aLineasNuevo) Then
MsgBox(4096,"Error", "Error al leer: " &$NFicheroNuevo& @error)
Exit
EndIf

For $iCont= 1 to $aLineasNuevo[0]
$SeparaenTrozos=StringSplit($aLineasNuevo[$iCont],"|",1)
if $aCodNuevo[0]="" then
$aCodNuevo[0]=$SeparaenTrozos[5]
Else
_ArrayAdd ( $aCodNuevo, $SeparaenTrozos[5] )
EndIf
GUICtrlSetData ( $LFicheroNuevo, "Leyendo Nuevos: " & String(UBound($aCodNuevo)))
Next

but this crash at about the record 8500 and i dont know why.

An example of the lines and why I separe it in pieces and make the comparation in the 5th piece of the line:

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|804666|FLUMIL INFANTIL 100MG/SOB 30 SOBRES GRANU SOL ORAL|2.59|

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|800474|ACETILC FARMASIERRA 100MG 30 SOB MON GRA SOL O EFG|2.05|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|730549|ACETILCISTEINA BEXAL 100MG/SOB 30 SOB EFG|2.05|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|851683|ACETILCISTEINA MERCK 100MG GRANUL SOL ORAL 30 EFG|2.05|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|650158|ACETILCISTEINA CINFAMED 100MG 30 SOBRES SOL OR EFG|2.06|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|653992|ACETILCISTEINA ACOST 100MG 30 SOB POLV SUSP OR EFG|1.81|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|653884|ACETILCISTEINA UR 100MG 30 SOBR POLVO SOL ORAL EFG|1.8|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|656241|ACETILCISTEINA NORMON 100MG 30 SOBR GR SO ORAL EFG|1.75|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|650429|ACETILCISTEINA CINFA 100MG 30 SOBRES SOL OR EFG|1.81|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|652631|ACETILCISTEINA ANGENERICO 100MG 30 SOB PO S OR EFG|1.81|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|773366|ACETILCISTEINA SANDOZ 100MG/SOB 30 SOB GRAN OR EFG|2.05|EFG

A07400|ACETILCISTEINA 100 MG/SOB 30 SOBRES SUSPENSION ORAL|2.05|01/05/2007|788919|ACETILCISTEINA TARBIS 100MG/SOB 30 SOB MONODOS EFG|1.81|EFG

Any ideas to help me?

(I excuse me for my english and the poor explication of the problem.)

Thank you very much

_____________________________________________

You should provide us with the error you are getting, maybe it will help find a solution.

Link to comment
Share on other sites

@Nahuel: Nice job cleaning up that post.

@mailmaster: Please format your posts better in the future.

After Nahuel reformatted it, I could see a way to rewrite your code in the first part which should be much smaller and faster:

#include <file.au3>
#include <array.au3>

; Read file into array
Dim $NFicheroViejo = "C:\Temp\Test.txt"     ; File name
Dim $aCodViejo[1] ; Create array variable to hold file data
If Not _FileReadToArray($NFicheroViejo, $aCodViejo) Then
    MsgBox(16, "Error", "Imposible abrir el fichero " & $NFicheroViejo)
    Exit
EndIf

; Reduce each line to 5th element, delete line if empty or not formatted correctly
For $n = $aCodViejo[0] To 1 Step - 1 ; Loop array in reverse
    $SeparaenTrozos = StringSplit($aCodViejo[$n], "|")
    If $SeparaenTrozos[0] >= 5 Then
        $aCodViejo[$n] = $SeparaenTrozos[5]
    Else
        _ArrayDelete($aCodViejo, $n)
    EndIf
Next

; Restore line count after possibly deleting some lines
$aCodViejo[0] = UBound($aCodViejo) - 1

; Display results
_ArrayDisplay($aCodViejo, "Leyendo Viejos: " & $aCodViejo[0], 0)

Of course, there is code missing for the GUI with the $LFicheroViejo control, so I replaced that with an _ArrayDisplay() at the end. The file name in $NFicheroViejo was not provide so I put in a test value just so I could follow what was going on and test it. You will have to remove those lines or change their value as required.

This version reads the whole file into an array with _FileReadToArray(), then loops through the array backwards to reduce each line to just the 5th element delimited by "|". Any line that is empty or has less than 5 such elements is deleted from the array. At the end, the remaining lines are re-counted by Ubound() and the count is placed in $aCodViejo[0].

I put your sample file data in "C:\Temp\Test.txt" and tested it. Seems to work fine. Because it only has to read the file once, then only has to loop through the array once, it should be fairly fast.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I excuse myself for the incovenience created to everybody and thanks specially to the cleaner.

I'm so sorry, but it's my first post.

No problem, just have pity on those who might want to read your code and help you out. And welcome to AutoIt. :)

Did you try the code I posted above, or come up with another solution?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I excuse myself for the incovenience created to everybody and thanks specially to the cleaner.

I'm so sorry, but it's my first post.

Oh, no worries :) Welcome to the forums.

Did you try PsaltyDs' code?

Also, couldn't help noticing your script is in Spanish, where are you from?

Edited by Nahuel
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...