evod510 Posted March 17, 2004 Share Posted March 17, 2004 (edited) Greetings, First of all thank you for making this program I need help , i dont know whether autoit can do it or not I have a string of text(combination of 88 byte ) which look like this 10371512711635 +00011619000+00000000000+00000000000+00000000000+00000000000+000000000 each byte/count have its own meaning, example the 1st byte/count lets say 5 is the product key , the 2nd byte/count 10 is the product code I need to separete the code to look something like this 10371;512711635 +;00011619000+;00000000000+;etc the reason is to import the files into excel , and it will be in its own column after that i need to convert the product key to its description example 10371 is apple etc Hope you understand and I hope somebody can help. Thanks Edited March 17, 2004 by evod510 Link to comment Share on other sites More sharing options...
CyberSlug Posted March 17, 2004 Share Posted March 17, 2004 (edited) So You want to put a semicolon after each plus sign and also after the first five characters. Here's one way:; Assume $keyCode is your string $tmp = StringReplace($keyCode, "+", "+;") $tmp = StringLeft($tmp,5) & ";" & StringTrimLeft($tmp, 5)P.S. You'll get quicker responses by posting questions to the support forum Edited March 17, 2004 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 More sharing options...
evod510 Posted March 17, 2004 Author Share Posted March 17, 2004 actually I did post the same question athttp://forums.devshed.com/t110240/s.htmli was trying to use phyton. It was bit difficult,and now i am trying to use autoit to solve the problemhelp please Link to comment Share on other sites More sharing options...
Developers Jos Posted March 17, 2004 Developers Share Posted March 17, 2004 what about something like this ? $var = "10371512711635 +00011619000+00000000000+00000000000+00000000000+00000000000+000000000" $out = StringMid($var,1,5) & ";" & StringReplace(StringTrimleft($var,6),'+','+;') SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
evod510 Posted March 23, 2004 Author Share Posted March 23, 2004 Greetings, First of all thanks for you help, but I think you misunderstand my question (i didnt explain correctly) I start from the beginning. i need to convert a file to a coma deliminated format ( so i can open that file using excel) I have a text file generated by another program. Lets say this is the content of the text file. abcd1234efgh5678i9j0k1l2mabcd1234efgh5678i9j0k1l2mabcd1234efgh5678i9j0k1l2m Each 25 strings contain code of one transaction so abcd1234efgh5678i9j0k1l2m contain "abcd"(string 1-4) as code product, "1234" (string 5-8) as code vendor, "efgh"(string 9-12) as code date, "5678" (string 13-16) as code location and "i9j0k1l2m"(string 17-25) as code value. Inside the file contain more than 1 transaction each transaction will use the same string format as above to record other transaction. ok i hope you understand so this is code that i wrote ;While 1 $file = FileOpen("test.txt", 0); open file $line = FileReadline($file) ; readline $code = StringMid($line, 1,4) ; read string $vendor = StringMid($line, 5,4) $date = StringMid($line, 9,4) $location = StringMid($line, 13,4) $value = StringMid($line, 17,9) $file2 = FileOpen("write.txt", 1); open file to write FileWrite($file2, $line & ";") FileWrite($file2, $code & ";") FileWrite($file2, $vendor & ";") FileWrite($file2, $date & ";") FileWrite($file2, $location & ";") FileWrite($file2, $value & @CRLF) ; each transaction will be on a newline FileClose($file) ;Wend I only manage to produce the first transaction, I did put the while function but it will loop forever and it will only take the first 25 string (first transaction). I got confuse with the while function. Please guide me. Thanks in advance ) Link to comment Share on other sites More sharing options...
Developers Jos Posted March 23, 2004 Developers Share Posted March 23, 2004 (edited) your script changed so it will read all records... ; open the file and test if ok $FILE = FileOpen("test.txt", 0); open file If $FILE = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $FILE2 = FileOpen("write.txt", 1); open file to write ; endless loop While 1 ; Read line and if @error then EOF so exit loop $LINE = FileReadLine($FILE) ; readline If @error = -1 Then ExitLoop $CODE = StringMid($LINE, 1,4); read string $VENDOR = StringMid($LINE, 5,4) $DATE = StringMid($LINE, 9,4) $LOCATION = StringMid($LINE, 13,4) $VALUE = StringMid($LINE, 17,9) ; write records FileWrite($FILE2, $LINE & ";") FileWrite($FILE2, $CODE & ";") FileWrite($FILE2, $VENDOR & ";") FileWrite($FILE2, $DATE & ";") FileWrite($FILE2, $LOCATION & ";") FileWrite($FILE2, $VALUE & @CRLF); each transaction will be on a newline Wend FileClose($FILE) FileClose($FILE2) Edited March 23, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
evod510 Posted March 24, 2004 Author Share Posted March 24, 2004 Thanks ( ) But it still show only the first transaction Link to comment Share on other sites More sharing options...
evod510 Posted March 24, 2004 Author Share Posted March 24, 2004 Here are the working code expandcollapse popup; ---------------------------------------------------------------------------- ; Count String ; ---------------------------------------------------------------------------- $FILE = FileOpen("test.txt", 0); open file If $FILE = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $chars = FileRead($file, 1) If @error = -1 Then ExitLoop $i=$i+1 Wend ; ---------------------------------------------------------------------------- ; Count Transaction In String ; ---------------------------------------------------------------------------- $trans = $i/25 FileClose($FILE) ; ---------------------------------------------------------------------------- ; Open File ; ---------------------------------------------------------------------------- $FILE = FileOpen("test.txt", 0); open file If $FILE = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $FILE2 = FileOpen("write.txt", 1); open file to write $LINE = FileReadLine($FILE) ; ---------------------------------------------------------------------------- ; Set Variable ; ---------------------------------------------------------------------------- Dim $y = 0 $ii = 0 $iii = 1 ; ---------------------------------------------------------------------------- ; Loop ; ---------------------------------------------------------------------------- Do Dim $xcode = $y+1 Dim $xVENDOR = $y+5 Dim $xDATE = $y+9 Dim $xLOCATION = $y+13 Dim $xVALUE = $y+17 ; ---------------- ;Read String ; ---------------- $CODE = StringMid($LINE, $xcode,4); read string $VENDOR = StringMid($LINE, $xVENDOR,4) $DATE = StringMid($LINE, $xDATE,4) $LOCATION = StringMid($LINE, $xLOCATION,4) $VALUE = StringMid($LINE, $xVALUE,9) ; ---------------- ;Write String ; ---------------- FileWrite($FILE2, $CODE & ";") FileWrite($FILE2, $VENDOR & ";") FileWrite($FILE2, $DATE & ";") FileWrite($FILE2, $LOCATION & ";") FileWrite($FILE2, $VALUE & @CRLF) ; ---------------- ;Adjust Variable ; ---------------- Dim $y=25*$iii $ii = $ii + 1 $iii = $ii + 1 Until $ii = $trans ; ---------------------------------------------------------------------------- ; End ; ---------------------------------------------------------------------------- MsgBox(0, "Transaction Recorded", $trans) FileClose($FILE) FileClose($FILE2) Anyway to shorten it Link to comment Share on other sites More sharing options...
Developers Jos Posted March 24, 2004 Developers Share Posted March 24, 2004 Looks to me that your input file doesn't contain regular End_Of_records (CRLF) so the whole thing is considered 1 record. Thats also probably why you get one output record. You are now reading all characters in one at the time and then spilt the record up on sections of 25 characters... So what characters is at pos 25 ? can that be used to split the record up into an array ? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
evod510 Posted March 25, 2004 Author Share Posted March 25, 2004 (edited) anything can be on string 25 actually the code above work ok maybe a bit long now i need to convert the code into its name if $CODE = abcd then $var1 = "Apple" endif if i got 10 code i have to put in 10 name. so i will have 10 if code. is there any otherway iis it possible to use array. Please Help Edited March 25, 2004 by evod510 Link to comment Share on other sites More sharing options...
Developers Jos Posted March 25, 2004 Developers Share Posted March 25, 2004 Sounds to me the easiest way is to use a IF on one line: if $CODE = abcd then $var1 = "Apple" SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
evod510 Posted March 26, 2004 Author Share Posted March 26, 2004 thanks .... need a bit more help what if the code entered is not recognise how do i make a condition for that?? Thanks Link to comment Share on other sites More sharing options...
Developers Jos Posted March 26, 2004 Developers Share Posted March 26, 2004 Then you could do a Select case like: Select Case $CODE = "abcd" $var1 = "Apple" Case $CODE = "xyz" $var1 = "banana" Case Else $var1 = "No Fruit" EndSelect SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
evod510 Posted March 29, 2004 Author Share Posted March 29, 2004 JdeB, Thanks a lot. Thanks again Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now