Jump to content

Need extra eyes to evaluate this...


Recommended Posts

I am sure it is my logic that is wrong some where. Basically I am taking a vertical text file like as follows.

*01 E/LI0001 /E07861

*01CLiechtenstein

*01U26/03/03

*02 Hilcona AG

*03 Bendererstrasse 21, FL-9494 Schaan, Liechtenstein

*04 Tel: 235 95 95

*04IInternational Tel: +423 235 95 95

*07 Fax: 232 02 85

*07IInternational Fax: +423 232 02 85

*0E Company Email: hilcona@hilcona.com

*0W Web Site: http://www.hilcona.com

*08 Board of Directors: Ekkehard Hilti (Präsident des Verwaltungsrats, Geschäftsführer Supply Chain), Jürgen Hilti (Vorsitzender der Geschäftsleitung), Fredy Eckert (Geschäftsführer Vertrieb GV Europa), Peter Luder (Geschäftsführer Category Management and Marktorganisation LEH-Schweiz), Heinz Allenspach (Geschäftsführer Corporate Services)

*10 Senior Executives: M Mayenknecht (Leiter Finanzwesen), Bernd Wurster (Leiter Personalwesen), Urs Egli (Leiter Beschaffung), Conrad Rührnschopf (Leiter Kommunikation)

*11 PRINCIPAL ACTIVITIES: Production, export and wholesale trade in chilled fresh products including pasta, sauces, pizza, ready-to-serve meals; deep-frozen products including pasta, stir-fries, gratins; deep-frozen products including soups, sauces, ready-to-serve meals, potato specialities

*12 Trade Names: hilcona, private label

*16 Group Companies: (100% owned): Hilcona Gourmet SA (Switzerland); Hilcona Feinkost GmbH (Germany); Hilcona France SA (France)

*16CFrance,Germany,Switzerland

*17 Principal Banks: LGT Bank in Liechtenstein AG; Verwaltungs und Privatbank AG; SBV; SVB; Liechtensteinische Landesbank

*18 Financial Information: Consolidated figures

*19D!2001!2002

*19C!SF'000!SF'000

*19 Sales turnover!272,000!287,000

*1P Status: Non-quoted public company

*20 Principal Shareholders: Hilti Family

*22TNo of Employees: 1,000 (Group figure)

*22N1000

*25p5141

*25 5142

*25 5149

*$SI 172769

*$TY S

*$BT 0

*$AT 0

*RA1 172.76

And turning it into a .csv file with the | as the seperator. Below is the script.

Dim $file, $line, $i, $j, $file1, $fileS, $fileO, $newLine, $leftLine, $lastLine

$fileO = FileOpenDialog("Select CSV", @ScriptDir, "CSV (*.csv)", 1)
$fileS = FileSaveDialog("Save new CSV", @ScriptDir, "CSV (*.csv)", 16)
If StringRight($fileS, 4) <> ".csv" Then
    $fileS &= ".csv"
EndIf

$file = FileOpen($fileO, 0)
If $file = -1 Then Exit
    
$file1 = FileOpen($fileS, 2)
If $file1 = -1 Then Exit
    
FileWriteLine($file1, "*02|*03|*04I|*05|*06|*07I|*08|*09|*10|*11")

$i = 1
$j = 0

While 1
    $line = FileReadLine($file, $i)
    If @error = -1 Then ExitLoop
    $leftLine = StringLeft($line, 4)
    
    If $leftLine = "*02 " OR $leftLine = "*03 " OR $leftLine = "*04I" OR $leftLine = "*05 " OR $leftLine = "*06 " OR $leftLine = "*07I" OR $leftLine = "*08 " OR $leftLine = "*09 " OR $leftLine = "*10 " OR $leftLine = "*11 " Then
        $lastLine = $leftLine
        $newLine &= _ReWrite($line)
        $j += 1
    Else
        $leftLine = ""
    EndIf
    
    If $leftLine = "" AND $lastLine = "*02 " Then
        $newLine &= _ReWrite("")
        $j += 1
    ElseIf $leftLine = "" AND $lastLine = "*03 " Then
        $newLine &= _ReWrite("")
        $j += 1
    ElseIf $leftLine = "" AND $lastLine = "*04I" Then
        $newLine &= _ReWrite("")
        $j += 1
    ElseIf $leftLine = "" AND $lastLine = "*05 " Then
        $newLine &= _ReWrite("")
        $j += 1
    ElseIf $leftLine = "" AND $lastLine = "*06 " Then
        $newLine &= _ReWrite("")
        $j += 1
    ElseIf $leftLine = "" AND $lastLine = "*07I" Then
        $newLine &= _ReWrite("")
        $j += 1
    ElseIf $leftLIne = "" AND $lastLine = "*08 " Then
        $newLine &= _ReWrite("")
        $j += 1
    ElseIf $leftLine = "" AND $lastLine = "*09 " Then
        $newLine &= _ReWrite("")
        $j += 1
    ElseIf $leftLine = "" AND $lastLine = "*10 " Then
        $newLine &= _ReWrite("")
        $j += 1
    ElseIf $leftLine = "" AND $lastLine = "*11 " Then
        $newLine &= _ReWrite("")
        $j += 1
    EndIf
;MsgBox(0, "Test", "Debug: " & $lastLine)
    $i += 1
    If $j = 11 Then
        _WriteParse($newLine)
        $j = 0
        $newLine = ""
        $lastLine = ""
    EndIf
WEnd

FileClose($file)
FileClose($file1)

Func _ReWrite($string)
    If $string = "" Then Return "|"
    $trimL = StringTrimLeft($string, 4)
    
    Return $trimL & "|"
EndFunc

Func _WriteParse($string)
    FileWriteLine($file1, $string)
EndFunc

This is what it outputs in the .csv file.

*02|*03|*04I|*05|*06|*07I|*08|*09|*10|*11

Hilcona AG|Bendererstrasse 21, FL-9494 Schaan, Liechtenstein||International Tel: +423 235 95 95||International Fax: +423 232 02 85|||Board of Directors: Ekkehard Hilti (Präsident des Verwaltungsrats, Geschäftsführer Supply Chain), Jürgen Hilti (Vorsitzender der Geschäftsleitung), Fredy Eckert (Geschäftsführer Vertrieb GV Europa), Peter Luder (Geschäftsführer Category Management and Marktorganisation LEH-Schweiz), Heinz Allenspach (Geschäftsführer Corporate Services)|Senior Executives: M Mayenknecht (Leiter Finanzwesen), Bernd Wurster (Leiter Personalwesen), Urs Egli (Leiter Beschaffung), Conrad Rührnschopf (Leiter Kommunikation)|PRINCIPAL ACTIVITIES: Production, export and wholesale trade in chilled fresh products including pasta, sauces, pizza, ready-to-serve meals; deep-frozen products including pasta, stir-fries, gratins; deep-frozen products including soups, sauces, ready-to-serve meals, potato specialities|

Obviously the files are larger than this, but it is practically the same all the way through.

Let me know if you can find anything wrong with my script. :P

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

What is the output supposed to look like?

My mistake... I thought I had made it obvious.

Supposed to look like the following. The first line is basically the header line. Those are the only lines I need to grab.

*02|*03|*04I|*05|*06|*07I|*08|*09|*10|*11

Hilcona AG|Bendererstrasse 21, FL-9494 Schaan, Liechtenstein|International Tel: +423 235 95 95|||International Fax: +423 232 02 85|||Board of Directors: Ekkehard Hilti (Präsident des Verwaltungsrats, Geschäftsführer Supply Chain), Jürgen Hilti (Vorsitzender der Geschäftsleitung), Fredy Eckert (Geschäftsführer Vertrieb GV Europa), Peter Luder (Geschäftsführer Category Management and Marktorganisation LEH-Schweiz), Heinz Allenspach (Geschäftsführer Corporate Services)|Senior Executives: M Mayenknecht (Leiter Finanzwesen), Bernd Wurster (Leiter Personalwesen), Urs Egli (Leiter Beschaffung), Conrad Rührnschopf (Leiter Kommunikation)|PRINCIPAL ACTIVITIES: Production, export and wholesale trade in chilled fresh products including pasta, sauces, pizza, ready-to-serve meals; deep-frozen products including pasta, stir-fries, gratins; deep-frozen products including soups, sauces, ready-to-serve meals, potato specialities

This one is different in 3 ways. One no "|" on the end. Two and Three I took the "|" before 'International Tel:' (*04I) and put it after. That should load into a .csv program like excel nicely.

Let me know if this doesnt make sense. I appreciate your time you are taking on this.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Keep in mind that I'm lazy and don't always run example code :P

EDIT: On closer look you have more pipes between the international fax and board of directors :lmao: so my code probably won't work.

Anyway, sorry for the delay. I *think* the following will work. But it's rather hackish, and the functions I use, though short in length, might be long in execution time.

My example takes a hard-coded file name input and just shows the output in a MessageBox:

First version is lazy:

Dim $fileName = "data.txt"

Dim $data = FileRead($fileName, FileGetSize($fileName))
Dim $lineEnding = @CRLF
If Not StringInStr($data, @CR) Then $lineEnding = @LF
Dim $output = "*02|*03|*04I|*05|*06|*07I|*08|*09|*10|*11" & $lineEnding

$output = $output & mySubstr($data, "*02", $lineEnding) & "|"
$output = $output & mySubstr($data, "*03", $lineEnding) & "|"
$output = $output & mySubstr($data, "*04I", $lineEnding) & "|"
$output = $output & mySubstr($data, "*05", $lineEnding) & "|"
$output = $output & mySubstr($data, "*06", $lineEnding) & "|"
$output = $output & mySubstr($data, "*07I", $lineEnding) & "|"
$output = $output & mySubstr($data, "*08", $lineEnding) & "|"
$output = $output & mySubstr($data, "*09", $lineEnding) & "|"
$output = $output & mySubstr($data, "*10", $lineEnding) & "|"
$output = $output & mySubstr($data, "*11", $lineEnding)

MsgBox(4096,"Result", $output)

; Returns the substring between x and y (Exclusive)
Func mySubstr($source, $x, $y)
    Local $posX, $posY, $tempTrunc
    $posX = StringInStr($source, $x); + StringLen($x)
; I want to find the first appearance of $y AFTER $x occurs
; Since StringInStr won't allow a starting index, remove the portion prior to $x
; The fact that StringMid takes a count argument simplifies the offset readjustment
    $tempTrunc = StringMid($source, $posX)
    $posY = StringInStr($tempTrunc, $y)
    If $posY = 0 Then Return "";return nothing if $y isn't found
    Return StringMid($source, $posX+StringLen($x), $posY-StringLen($x)-1)
EndFunc

Second version optimizes redundant code with StringSplit:

Dim $fileName = "data.txt"

Dim $data = FileRead($fileName, FileGetSize($fileName))
Dim $lineEnding = @CRLF
If Not StringInStr($data, @CR) Then $lineEnding = @LF

Dim $output = "*02|*03|*04I|*05|*06|*07I|*08|*09|*10|*11"
$specialValues = StringSplit($output, "|")

$output = $output & $lineEnding
For $i =  1 to $specialValues[0]
    $output = $output & mySubstr($data, $specialValues[$i], $lineEnding) & "|"
Next
$output = StringTrimRight($output, 1);remove trailing pipe

MsgBox(4096,"Result", $output)

; Returns the substring between x and y (Exclusive)
Func mySubstr($source, $x, $y)
    Local $posX, $posY, $tempTrunc
    $posX = StringInStr($source, $x); + StringLen($x)
    $tempTrunc = StringMid($source, $posX)
    $posY = StringInStr($tempTrunc, $y)
    If $posY = 0 Then Return "";return nothing if $y isn't found
    Return StringMid($source, $posX+StringLen($x), $posY-StringLen($x)-1)
EndFunc
Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Keep in mind that I'm lazy and don't always run example code :P

EDIT: On closer look you have more pipes between the international fax and board of directors :lmao: so my code probably won't work.

Anyway, sorry for the delay. I *think* the following will work. But it's rather hackish, and the functions I use, though short in length, might be long in execution time.

My example takes a hard-coded file name input and just shows the output in a MessageBox:

First version is lazy:

Dim $fileName = "data.txt"

Dim $data = FileRead($fileName, FileGetSize($fileName))
Dim $lineEnding = @CRLF
If Not StringInStr($data, @CR) Then $lineEnding = @LF
Dim $output = "*02|*03|*04I|*05|*06|*07I|*08|*09|*10|*11" & $lineEnding

$output = $output & mySubstr($data, "*02", $lineEnding) & "|"
$output = $output & mySubstr($data, "*03", $lineEnding) & "|"
$output = $output & mySubstr($data, "*04I", $lineEnding) & "|"
$output = $output & mySubstr($data, "*05", $lineEnding) & "|"
$output = $output & mySubstr($data, "*06", $lineEnding) & "|"
$output = $output & mySubstr($data, "*07I", $lineEnding) & "|"
$output = $output & mySubstr($data, "*08", $lineEnding) & "|"
$output = $output & mySubstr($data, "*09", $lineEnding) & "|"
$output = $output & mySubstr($data, "*10", $lineEnding) & "|"
$output = $output & mySubstr($data, "*11", $lineEnding)

MsgBox(4096,"Result", $output)

; Returns the substring between x and y (Exclusive)
Func mySubstr($source, $x, $y)
    Local $posX, $posY, $tempTrunc
    $posX = StringInStr($source, $x); + StringLen($x)
; I want to find the first appearance of $y AFTER $x occurs
; Since StringInStr won't allow a starting index, remove the portion prior to $x
; The fact that StringMid takes a count argument simplifies the offset readjustment
    $tempTrunc = StringMid($source, $posX)
    $posY = StringInStr($tempTrunc, $y)
    If $posY = 0 Then Return "";return nothing if $y isn't found
    Return StringMid($source, $posX+StringLen($x), $posY-StringLen($x)-1)
EndFunc

Second version optimizes redundant code with StringSplit:

Dim $fileName = "data.txt"

Dim $data = FileRead($fileName, FileGetSize($fileName))
Dim $lineEnding = @CRLF
If Not StringInStr($data, @CR) Then $lineEnding = @LF

Dim $output = "*02|*03|*04I|*05|*06|*07I|*08|*09|*10|*11"
$specialValues = StringSplit($output, "|")

$output = $output & $lineEnding
For $i =  1 to $specialValues[0]
    $output = $output & mySubstr($data, $specialValues[$i], $lineEnding) & "|"
Next
$output = StringTrimRight($output, 1);remove trailing pipe

MsgBox(4096,"Result", $output)

; Returns the substring between x and y (Exclusive)
Func mySubstr($source, $x, $y)
    Local $posX, $posY, $tempTrunc
    $posX = StringInStr($source, $x); + StringLen($x)
    $tempTrunc = StringMid($source, $posX)
    $posY = StringInStr($tempTrunc, $y)
    If $posY = 0 Then Return "";return nothing if $y isn't found
    Return StringMid($source, $posX+StringLen($x), $posY-StringLen($x)-1)
EndFunc
I appreciate the fresh look at things. I have taken a peek at the code. I even ran it on my file. It only sends one output. I have many sets of data for it to go through. Hence the reason for my method. Though yours has inspired my thoughts in a new direction. I will repost with some more questions if I run upon them.

Thanks a million,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Again here is what I have come up with so far. This time I am including the two files I have, that I have been testing on.

#include <file.au3>

Dim $line, $newLine, $aLine, $lastLine, $i, $x, $nextLine, $nextLine, $notLine
Dim $firstLine = "*02|*03|*04I|*05|*06|*07I|*08|*09|*10|*11"
Dim $splitLine = StringSplit($firstLine, "|")

Dim $fileO = FileOpenDialog("Select CSV", @ScriptDir, "CSV (*.csv)", 1)

Dim $fileS = FileSaveDialog("Save new CSV", @ScriptDir, "CSV (*.csv)", 16)
If StringRight($fileS, 4) <> ".csv" Then
    $fileS &= ".csv"
EndIf
    
Dim $file = FileOpen($fileS, 2)
If $file = -1 Then Exit
    
FileWriteLine($file, $firstLine)

If Not _FileReadToArray($fileO, $aLine) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

For $i = 1 To $aLine[0] Step 1
    $lastLine = StringLeft($aLine[$i-1], 4)
    $thisLine = StringLeft($aLine[$i], 4)
    $nextLine = StringLeft($aLine[$i+1], 4)
    _LineSelect($aLine[$i])
    If Not $notLine Then
        For $j = 1 to $splitLine[0] Step 1
            If $thisLine = $splitLine[$j] AND Not($lastLine = $splitLine[$j-1]) Then
                $newLine &= "|"
            EndIf
            If $thisLine = $splitLine[$j] AND Not($nextLine = $splitLine[$j+1]) Then
                $newLine &= "|"
            EndIf
        Next
    EndIf
;MsgBox(0, "Test $newLine", "$newLine: " & @CRLF & $newLine)
Next

FileClose($file)

Func _LineSelect($sLine)
    For $x = 1 To $splitLine[0] Step 1
        If StringLeft($sLine, StringLen($splitLine[$x])) = $splitLine[$x] Then
            If Not($splitLine[$x] = "*04I" OR $splitLine[$x] = "*07I" OR StringMid($sLine, 4, 1) = " ") Then
                $notLine = 1
                Return
            EndIf
            $newLine &= StringTrimLeft($sLine, 4)
            If $x = $splitLine[0] Then
                _WriteParse($newLine)
                $newLine = ""
            ElseIf $x < $splitLine[0] Then
                $newLine &= "|"
            EndIf
            
            $notLine = 0
            Return
        EndIf
    Next
EndFunc

Func _WriteParse($string)
    FileWriteLine($file, $string)
EndFunc

I believe the code that is in between If $notLine Then...EndIf is where the code needs repair, but I have been racking my brain. I am alot closer. I have the first 3 columns lining up when I import into OpenOffice or Excel.

I hope someone can help. The .zip also has the script file.

TIA for the Help,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

#include <Array.au3>

; first you have this

Dim $firstLine = "*02|*03|*04I|*05|*06|*07I|*08|*09|*10|*11"

Dim $splitLine = StringSplit($firstLine, "|")

_ArrayDisplay ( $splitLine, "test" )

; then you have this

$thisLine = StringLeft($aLine[$i], 4)

; the arraydisplay indicates that not all of the arrays contain "4" characters.. ( 3 and 4 characters)

; so how could they test to be equal

maybe strin in string???

or am i way off??

just trying to help

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

try to see what i can... first thing i noticed was it created a file with fileOpen()

Dim $fileO = FileOpenDialog("Select CSV", @ScriptDir, "CSV (*.csv)", 1)
If @error Then
    MsgBox(4096,"","No File(s) chosen")
    Exit
EndIf

this small snipet will prevent that

8)

Okay I see where that could be useful. I will include that error check.

maybe strin in string???

or am i way off??

just trying to help

8)

I dont understand where StringInStr() would help. The only place I recall using the 4 is when I needed to either grab the 4 characters... Because it is the first 4 that really matter. Some of the first 4 have a space after the 3, and the others have the I as in 4I and 7I.

Did you download the zip file? It I think would be more helpful as it contains the information I am trying to parse.

Thanks for the thoughts.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

i made the small script above... but this is my question - directly

the number [1] instance of stringsplit($firstLine) is 3 charactors

the number in the string left is 4 characters

$firstLine_1 = "*02"
 
 Dim $aLine_1 = "*02 123456"
 $thisLine = StringLeft($aLine_1, 4)
 
 If $firstLine_1 = $thisLine Then
    MsgBox(0,"test ok", $firstLine_1 & "   " & $thisLine )
Else
    MsgBox(0,"test NOT ok", $firstLine_1 & "   " & $thisLine )
EndIf

try this code

8)

NEWHeader1.png

Link to comment
Share on other sites

i made the small script above... but this is my question - directly

the number [1] instance of stringsplit($firstLine) is 3 charactors

the number in the string left is 4 characters

$firstLine_1 = "*02"
 
 Dim $aLine_1 = "*02 123456"
 $thisLine = StringLeft($aLine_1, 4)
 
 If $firstLine_1 = $thisLine Then
    MsgBox(0,"test ok", $firstLine_1 & "   " & $thisLine )
Else
    MsgBox(0,"test NOT ok", $firstLine_1 & "   " & $thisLine )
EndIf

try this code

8)

I understand what you are meaning, but I tried to implement that thought into my code by adding spaces to the $firstLine, and when I did the output wasnt as desired. I didnt know how to work with it from there.

Have you tried running my script and seen the output?

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Have you tried running my script and seen the output?

of course... and many times

I didnt know how to work with it from there.

.. in the function _LineSelect($sLine)... you used this

If StringLeft($sLine, StringLen($splitLine[$x])) = $splitLine[$x] Then

you could maybe use stringinstr()

maybe change this

If $thisLine = $splitLine[$j] AND Not($lastLine = $splitLine[$j-1]) Then

to

If StringInStr($thisLine, $splitLine[$j]) And Not StringInStr($lastLine, $splitLine[$j-1]) Then

****** not tested

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Maybe if I explain a little bit of why I am doing it the way I am. That code if taken out makes the whole first 3 columns of data not line up properly. I need a slight addition. Maybe an AND statement on the end of those If's to not have so many |'s where not needed. :P It over does what it needs to.

Try importing the ztest.csv into Excel or Calc. Of course "|" is the seperator. You will notice how bad the columns miss align.

I have re-written this about 3 times already. :-/

When I tried your code example it just messed up my output again. Not a bad idea, but not what is needed.

I just cant seem to explain exactly what I need.

Edit: With my current code my first line is good up until *07I, then it adds two |'s that I dont need. Which are from both of those If statements. That is the area I need help I do believe, I just need the correct number of |'s :-/.

Edit2: Below is the new code. It provides the same output, but (I think) takes care of all of your concerns.

#include <file.au3>

Dim $line, $newLine, $aLine, $lastLine, $i, $x, $nextLine, $nextLine, $notLine
Dim $firstLine = "*02 |*03 |*04I|*05 |*06 |*07I|*08 |*09 |*10 |*11 "
Dim $splitLine = StringSplit($firstLine, "|")

Dim $fileO = FileOpenDialog("Select CSV", @ScriptDir, "CSV (*.csv)", 1)
If @error Then
    MsgBox(0, "ERROR", "No file selected. Please re-run and select a file." & @CRLF & "Exiting...")
    Exit
EndIf

Dim $fileS = FileSaveDialog("Save new CSV", @ScriptDir, "CSV (*.csv)", 16)
If StringRight($fileS, 4) <> ".csv" Then
    $fileS &= ".csv"
EndIf
    
Dim $file = FileOpen($fileS, 2)
If $file = -1 Then Exit
    
FileWriteLine($file, $firstLine)

If Not _FileReadToArray($fileO, $aLine) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

For $i = 1 To $aLine[0] Step 1
    $lastLine = StringLeft($aLine[$i-1], 4)
    $thisLine = StringLeft($aLine[$i], 4)
    $nextLine = StringLeft($aLine[$i+1], 4)
    _LineSelect($aLine[$i])
    If Not $notLine Then
        For $j = 1 to $splitLine[0] Step 1
            If $thisLine = $splitLine[$j] AND (Not($lastLine = $splitLine[$j-1]) OR Not($nextLine = $splitLine[$j+1])) Then
                $newLine &= "|"
            EndIf
        Next
    EndIf
Next

FileClose($file)

Func _LineSelect($sLine)
    For $x = 1 To $splitLine[0] Step 1
        If StringLeft($sLine, StringLen($splitLine[$x])) = $splitLine[$x] Then
            If Not($splitLine[$x] = "*04I" OR $splitLine[$x] = "*07I" OR StringMid($sLine, 4, 1) = " ") Then
                $notLine = 1
                Return
            EndIf
            $newLine &= StringTrimLeft($sLine, 4)
            If $x = $splitLine[0] Then
                _WriteParse($newLine)
                $newLine = ""
            ElseIf $x < $splitLine[0] Then
                $newLine &= "|"
            EndIf
            
            $notLine = 0
            Return
        EndIf
    Next
EndFunc

Func _WriteParse($string)
    FileWriteLine($file, $string)
EndFunc

JS

Edited by JSThePatriot

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

also... i noticed

If Not($splitLine[$x] = "*04I" OR $splitLine[$x] = "*07I" OR StringMid($sLine, 4, 1) = " ") Then

that means

($splitLine[$x] = "*04I" ; not ok

$splitLine[$x] = "*07I" ; is ok

StringMid($sLine, 4, 1) = " " ; is ok

right???

or is it supposed to be like this

If Not($splitLine[$x] = "*04I" OR Not $splitLine[$x] = "*07I" OR Not StringMid($sLine, 4, 1) = " ") Then

just checking

8)

NEWHeader1.png

Link to comment
Share on other sites

Maybe if I explain a little bit of why I am doing it the way I am. That code if taken out makes the whole first 3 columns of data not line up properly. I need a slight addition. Maybe an AND statement on the end of those If's to not have so many |'s where not needed. :P It over does what it needs to.

Try importing the ztest.csv into Excel or Calc. Of course "|" is the seperator. You will notice how bad the columns miss align.

I have re-written this about 3 times already. :-/

When I tried your code example it just messed up my output again. Not a bad idea, but not what is needed.

I just cant seem to explain exactly what I need.

JS

i have always thought that CSV files were Comma "," delimited

i thought it was strange how you put the "|"

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

try this

$test = " "

For $x = 1 to 40
    $test = $test & "Test line number " & $x & ","
Next

FileWrite("C:\temp\test.csv", $test)

$test = " "

For $x = 1 to 40
    $test = $test & "Test line number " & $x & "|"
Next

FileWrite("C:\temp\test2.csv", $test)

the "|" doesnt work

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

revised your latest... works much better

#include <file.au3>

Dim $line, $newLine, $aLine, $lastLine, $i, $x, $nextLine, $nextLine, $notLine
Dim $firstLine = "*02 ,*03 ,*04I,*05 ,*06 ,*07I,*08 ,*09 ,*10 ,*11 "
Dim $splitLine = StringSplit($firstLine, ",")

Dim $fileO = FileOpenDialog("Select CSV", @ScriptDir, "CSV (*.csv)", 1)
If @error Then
    MsgBox(0, "ERROR", "No file selected. Please re-run and select a file." & @CRLF & "Exiting...")
    Exit
EndIf

Dim $fileS = FileSaveDialog("Save new CSV", @ScriptDir, "CSV (*.csv)", 16)
If StringRight($fileS, 4) <> ".csv" Then
    $fileS &= ".csv"
EndIf
    
Dim $file = FileOpen($fileS, 2)
If $file = -1 Then Exit
    
FileWriteLine($file, $firstLine)

If Not _FileReadToArray($fileO, $aLine) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

For $i = 1 To $aLine[0] Step 1
    $lastLine = StringLeft($aLine[$i-1], 4)
    $thisLine = StringLeft($aLine[$i], 4)
    If $i < $aline[0] Then $nextLine = StringLeft($aLine[$i+1], 4)
    _LineSelect($aLine[$i])
    If Not $notLine Then
        For $j = 1 to $splitLine[0] Step 1
            If $thisLine = $splitLine[$j] AND (Not($lastLine = $splitLine[$j-1])) Then
                If $j < $splitLine[0] And Not($nextLine = $splitLine[$j+1]) Then
                    $newLine &= ","
                EndIf
                If $j = $splitLine[0] Then
                    $newLine &= ","
                EndIf
            EndIf
        Next
    EndIf
Next

FileClose($file)

Func _LineSelect($sLine)
    For $x = 1 To $splitLine[0] Step 1
        If StringLeft($sLine, StringLen($splitLine[$x])) = $splitLine[$x] Then
            If Not($splitLine[$x] = "*04I" OR $splitLine[$x] = "*07I" OR StringMid($sLine, 4, 1) = " ") Then
                $notLine = 1
                Return
            EndIf
            $newLine &= StringTrimLeft($sLine, 4)
            If $x = $splitLine[0] Then
                _WriteParse($newLine)
                $newLine = ""
            ElseIf $x < $splitLine[0] Then
                $newLine &= ","
            EndIf
            
            $notLine = 0
            Return
        EndIf
    Next
EndFunc

Func _WriteParse($string)
    FileWriteLine($file, $string)
EndFunc

i dont know what parts you want.. and are missing from the output...

but this should help ALOT!!

8)

NEWHeader1.png

Link to comment
Share on other sites

also... i noticed

If Not($splitLine[$x] = "*04I" OR $splitLine[$x] = "*07I" OR StringMid($sLine, 4, 1) = " ") Then

that means

($splitLine[$x] = "*04I" ; not ok

$splitLine[$x] = "*07I" ; is ok

StringMid($sLine, 4, 1) = " " ; is ok

right???

or is it supposed to be like this

If Not($splitLine[$x] = "*04I" OR Not $splitLine[$x] = "*07I" OR Not StringMid($sLine, 4, 1) = " ") Then

just checking

8)

Your second example is the end result of the code. I have it in ()'s for that reason. Just shortening code. Also it only checks to see if it is false once instead of 3 times. That line works like a charm. (To my knowledge anyways). lol

i have always thought that CSV files were Comma "," delimited

i thought it was strange how you put the "|"

8)

Well CSV = Comma Seperated Values. So yes *.csv files are generally comma seperated, but dont have to be. That was the original concept, but if you are having sentances or anything else then that ended up not being good. I actually tried comma's first because that naturally is the default, but that didnt work out, so i used the pipe. I could have used any other character(s) so long as they were unique.

I hope that answers your questions for now. :P

I am still mulling over it. I think I am fixing to add a case statement that just checks to see how many pipes there are and tries to calculate how many there should be.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

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...