Jump to content

Txt to CSV and some other information...


Recommended Posts

Hi AutoIters :D How are you guys? Water, everything ok? :) I'm here to ask you guys if there is a way to convert a formatted .txt ( created by an AutoIt script ) in a formatted .csv... My script create the file with the pattern "Column1";"Column2";"Column...n"; , and I have to maintain the same format... Does anyone know about UDF or any suggestion about it? I would like to know some information about a thing that is a bit complicated to explain... I have very large rows of code, and I have to scroll horizontally to see what's there at the end of the line... I saw something like 
 

Very long code... _
Continue of the long code

Can anyone please explain this thing to me? And where I can apply this method to have a single declaration or operation in several rows... Thanks guys for your help! Have a good day! :) Francesco

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

@1: It sounds like your script outputs exactly what you want already? Just output it to another filename, or copy/rename the resulting .txt file to a csv... If you actually have to parse things, please provide an example of a few lines of input and a few lines of expected/required output.

 

@2: a line ending in a space followed by an underscore escapes the newline, so it acts like everything is on one line. You can't break strings or numbers or variable names (etc) in this way, but whereever there's a space in the code you could break it with that technique.

MsgBox( _
0 _
,0, _
"hello" _
)

 

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Just now, SadBunny said:

@1: It sounds like your script outputs exactly what you want already? Just output it to another filename, or copy/rename the resulting .txt file to a csv... If you actually have to parse things, please provide an example of a few lines of input and a few lines of expected/required output.

 

@2: a line ending in a space followed by an underscore escapes the newline, so it acts like everything is on one line. You can't break strings or numbers or variable names (etc) in this way, but whereever there's a space in the code you could break it with that technique.

MsgBox( _
0 _
,0, _
"hello" _
)

 

Thank you for your reply SadBunny :) Bud, now arise another question... Why you are sad? Ahahahah, just kidding :) Hope all goes fine :) Yeah, my script write ( in a file ) lines like this: 

Local $sScriviRiga = '"AI";' & StringReplace($aResult[$i][0], "DBD_", $sNumeroDevice & "B10BY") & '"";"' & $aResult[$i][3] & '";"' & $aResult[$i][4] & '";"' & $aResult[$i][5] & '";"' & $aResult[$i][6] & '";"' & @CRLF
; Now I'm going to apply what you just taught me :)

I'm doing some changes to my script. As soon I've finished, I'll post my code here If I still have problems like characters changes ( ° with some strange A )... Thanks! :D

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Local $sScriviRiga =     '"AI"' & ';' &_ ; BLOCK TYPE
                                '"' & StringReplace($aResult[$i][0], "DBD_", $sNumeroDevice & "B10BY") & '";' &_ ; TAG
                                '""' & ';' &_ ; NEXT BLOCK
                                '"' & $aResult[$i][3] & '";' &_ ; DESCRIPTION
                                '"ON"' & ';' &_ ; INITIAL SCAN
                                '"1"' & ';' &_ ; SCAN TIME
                                '"0"' & ';' &_ ; SMOOTHING
                                '"SIX"' & ';' &_ ; I/O DEVICE
                                '""' & ';' &_; H/W OPTIONS
                                $sIndirizzoIO &_ ; I/O ADDRESS
                                '"FLT"' & ';' &_ ; SIGNAL CONDITIONING
                                '"' & $aExplodeStringEGU[0] & '";' &_ ; LOW EGU LIMIT
                                '"' & $aExplodeStringEGU[1] & '";' &_ ; HIGH EGU LIMIT
                                '"' & $aResult[$i][5] & '";' &_ ; EGU TAG
                                '"AUTO"' & ';' &_ ; INITIAL A/M STATUS
                                '"DISABLE"' & ';' &_ ; ALARME ENABLE
                                '"NONE"' & ';' &_ ; ALARM AREA(S)
                                '"-10.000,00"' & ';' &_ ; LO LO ALARM LIMIT
                                '"-10.000,00"' & ';' &_ ; LO ALARM LIMIT
                                '"10.000,00"' & ';' &_ ; HI ALARM LIMIT
                                '"10.000,00"' & ';' &_ ; HI HI ALARM LIMIT
                                '"0"' & ';' &_ ; ROC ALARM LIMIT
                                '"1.000,00"' & ';' &_ ; DEAD BAND
                                '"L"' & ';' &_ ; ALARM PRIORITY
                                '"YES"' & ';' &_ ; ENABLE OUTPUT
                                '""' & ';' &_ ; SECURITY AREA 1
                                '""' & ';' &_ ; SECURITY AREA 2
                                '""' & ';' &_ ; SECURITY AREA 3
                                '""' & ';' &_ ; ALARM AREA 1
                                '""' & ';' &_ ; ALARM AREA 2
                                '""' & ';' &_ ; ALARM AREA 3
                                '""' & ';' &_ ; ALARM AREA 4
                                '""' & ';' &_ ; ALARM AREA 5
                                '""' & ';' &_ ; ALARM AREA 6
                                '""' & ';' &_ ; ALARM AREA 7
                                '""' & ';' &_ ; ALARM AREA 8
                                '""' & ';' &_ ; ALARM AREA 9
                                '""' & ';' &_ ; ALARM AREA 10
                                '""' & ';' &_ ; ALARM AREA 11
                                '""' & ';' &_ ; ALARM AREA 12
                                '""' & ';' &_ ; ALARM AREA 13
                                '""' & ';' &_ ; ALARM AREA 14
                                '""' & ';' &_ ; ALARM AREA 15
                                '""' & ';' &_ ; USER FIELD 1
                                '""' & ';' &_ ; USER FIELD 2
                                '"NONE"' & ';' &_ ; ESIG TYPE
                                '"YES"' & ';' &_ ; ESIG ALLOW CONT USE
                                '"NO"' & ';' &_ ; ESIG XMPT ALARM ACK
                                '"REJECT"' & ';' &_ ; ESIG UNSIGNED WRITES
                                @CRLF

Obviously, this doesn't work... 
PS: Because it's a big string... Are there any ways to do it? Thanks :)
PPS: I thought something like an array, and every string is an element of the array... Idk!  Waiting for some suggestion! :D 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

You need to prefix every underscore by a space. (Press ctrl+H in Scite to search&replace, then replace &_ by & _ (so with a space between them).

After that, this code still doesn't work on its own because there's a bunch of undeclared variables, but the syntax error should be gone.

 

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

1 hour ago, SadBunny said:

You need to prefix every underscore by a space. (Press ctrl+H in Scite to search&replace, then replace &_ by & _ (so with a space between them).

After that, this code still doesn't work on its own because there's a bunch of undeclared variables, but the syntax error should be gone.

 

I HAVE TO SAY A HUGE THANK YOU! :D Sorry for the "Caps lock" phrase, but it was intentional! Thank you SadBunny! I fixed &_ with & _ and the code works perfectly! About the variables, I posted a portion of the script :P The declaration is above those rows of code :D By the way, I'll keep you updated on the development of my script! Another big thank you to YOU and this beautiful community! I hope this language will never die, because it's amazing and we have to be proud of this community! Thank everyone for supporting this project! Have a good night :) Francesco 

 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

That depends on how your script reads the rows. But in general I'm guessing you probably loop through a bunch of lines. You have two general options:

1) Only output the output in required situations (i.e. in this case when Dxxx is NOT blank)

2) Do a test for Dxxx being blank (and any other exclusion rules) and skip the rest of the loop using ContinueLoop

 

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

15 hours ago, SadBunny said:

That depends on how your script reads the rows. But in general I'm guessing you probably loop through a bunch of lines. You have two general options:

1) Only output the output in required situations (i.e. in this case when Dxxx is NOT blank)

2) Do a test for Dxxx being blank (and any other exclusion rules) and skip the rest of the loop using ContinueLoop

 

Seems it works checking if a cell is blank, with this code:
 

If($aResult[$i][3] <> "") Then
    ;Do Something
Else
    ;Do Nothing
EndIf

The script only writes rows where that field ( Column 3, Row $i ), and it does nothing when that field is blank. 
Could it cause bug or anything else? Thank you :)
Now I'm working on fixing the export of the character "°" and ì,à charatcters :) Thanks for you help!

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

I'm having a "bug" with StringReplace... ( Maybe it's not a bug, but some "I can't take this format because I recognize that string as a number" (?) )
Try this code:
 

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

Local $sString = "0.0"
StringReplace($sString, ".", "B")
MsgBox($MB_ICONINFORMATION, "Nuova stringa", $sString)

The output won't be 0B0. Can you please explain to me why? 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Yes, I can.

The StringReplace function doesn't do the replacement action inside $sString. Instead it takes the value of $sString, does the replacement and returns the result of the replacement. This works:

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

Local $sString = "0.0"
$sReplacementResult = StringReplace($sString, ".", "B")
MsgBox($MB_ICONINFORMATION, "Nuova stringa", $sReplacementResult)

; You could of course also store the result of the replacement right back into the same string variable:
; $sString = StringReplace($sString, ".", "B")
; MsgBox($MB_ICONINFORMATION, "Nuova stringa", $sString)

 

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

4 minutes ago, SadBunny said:

Yes, I can.

The StringReplace function doesn't do the replacement action inside $sString. Instead it takes the value of $sString, does the replacement and returns the result of the replacement. This works:

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

Local $sString = "0.0"
$sReplacementResult = StringReplace($sString, ".", "B")
MsgBox($MB_ICONINFORMATION, "Nuova stringa", $sReplacementResult)

; You could of course also store the result of the replacement right back into the same string variable:
; $sString = StringReplace($sString, ".", "B")
; MsgBox($MB_ICONINFORMATION, "Nuova stringa", $sString)

 

Thanks for the reply SadBunny! I was trying and trying, and I've finally did it on my own... Now comes another "How to...".

In my read file, I've characters like ° or ì,à and so on... How can I let not variate them from the .txt to the .csv? 
Thanks <3 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

On 1/12/2016 at 4:51 PM, FrancescoDiMuro said:

How can I let not variate them from the .txt to the .csv? 

Why not use them as-is?

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

On 12/1/2016 at 11:21 AM, FrancescoDiMuro said:

In my read file, I've characters like ° or ì,à and so on... How can I let not variate them from the .txt to the .csv? 

How are you reading the file? If you use FileOpen() then try setting the mode parameter to $FO_UTF8_NOBOM (= 256) or $FO_UTF8 (= 128).

Edited by czardas
Link to comment
Share on other sites

On 3/12/2016 at 9:59 AM, czardas said:

How are you reading the file? If you use FileOpen() then try setting the mode parameter to $FO_UTF8_NOBOM (= 256) or $FO_UTF8 (= 128).

 

On 3/12/2016 at 7:09 AM, TheDcoder said:

Why not use them as-is?

Good mornig guys :)
@czardas: I open the file with FileOpen, yeah... So, I can try setting that paramater...

@TheDcoder Wut? Ahahahah :D 


Thanks for the help guys :)

 

 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

30 minutes ago, FrancescoDiMuro said:

 Wut? Ahahahah :D 

Sorry for confusing but I did not understand what you wanted to do :blink:. Here is a wild guess: is the text getting corrupted when you write to a file?

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

13 minutes ago, TheDcoder said:

Sorry for confusing but I did not understand what you wanted to do :blink:. Here is a wild guess: is the text getting corrupted when you write to a file?

Ahahahah, np :)
This is what I want: read character ° or ì or à -> have in the files I create those characters.
The issue occurs when I convert the file ( with FileMove ) the file I did create.
In the .txt that I did create I have °, à and so on, in the .csv I don't. That's my issue, and I don't know how to solve it. 
Thanks again for your reply :) 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

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