amakrkr Posted June 18, 2010 Posted June 18, 2010 Hello all, i have posted quite some questions regarding AutoIt and TXT files past week. And my script evolved from a simple Write to TXT file to a script which (hopefully) will insert information from THX to oracle database. Below my post you will find the code but first i want to ask for your help. I got few problems i need to solve so lets start. The problem i have is related to my TXT file. I am stuck at how to read lines from my file and seperate that line to a segments. Example: files.dat@21.12.2009@21:33 -> $part1 = files.dat , $part2 = 21.12.2009, $part3 = 21:33 I wanted to use that info later on, on my INSERT statment to oracle database. I have tried with StringSplit: for $i = 1 to ubound($list) -1 $read = FileReadLine($file) $split = StringSplit($read,'@') FileWriteLine($file_open,$split & @CRLF) Next ...but all i get is emptyness .
Moderators Melba23 Posted June 18, 2010 Moderators Posted June 18, 2010 amakrkr,Read the Help file for StringSplit - "Returns an array". So you need to read the individual elements of the array like this:$sData = "files.dat@21.12.2009@21:33" $aArray = StringSplit($sData, "@") MsgBox(0, "Split", $sData & @CRLF & @CRLF & "has been split into:" & @CRLF & @CRLF & $aArray[1] & @CRLF & $aArray[2] & @CRLF & $aArray[3])M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Zibit Posted June 18, 2010 Posted June 18, 2010 if you want to paste all of it then $i = 0 $split = $split = StringSplit($read,'@') do filewrite("file.txt", $split[$i]) until $i = $split[0] Creator Of Xtreme DevelopersPixel Pattern UDFTray GUI UDFMathssend & recive register scriptMouse Control via Webcam
amakrkr Posted June 18, 2010 Author Posted June 18, 2010 (edited) amakrkr, Read the Help file for StringSplit - "Returns an array". So you need to read the individual elements of the array like this: $sData = "files.dat@21.12.2009@21:33" $aArray = StringSplit($sData, "@") MsgBox(0, "Split", $sData & @CRLF & @CRLF & "has been split into:" & @CRLF & @CRLF & $aArray[1] & @CRLF & $aArray[2] & @CRLF & $aArray[3]) M23 Thank you for your fast replay. Problem i get when i try your code is "Arry variable has incorrect number of subscripts or subscript dimension range exceeded". $File = "c:\Filenames.dat" $data = FileReadLine($File) $aArray = StringSplit($data , "@") MsgBox(0, "Split", $data & @CRLF & @CRLF & "has been split into:" & @CRLF & @CRLF & $aArray[1] & @CRLF & $aArray[2] & @CRLF & $aArray[3]) if you want to paste all of it then $i = 0 $split = $split = StringSplit($read,'@') do filewrite("file.txt", $split[$i]) until $i = $split[0] Hello and thx for replay. When i tested this i got only "11111111" in my file. It looks like this is endless loop for some reason. I dont know if i am missing something but i thought StringSplit will return a string as a resoult or am i wrong? Edited June 18, 2010 by amakrkr
Moderators Melba23 Posted June 18, 2010 Moderators Posted June 18, 2010 amakrkr, I dont know if i am missing something but i thought StringSplit will return a string as a resoult or am i wrong?Did you read what i wrote above? Read the Help file for StringSplit - "Returns an array". As for the error: Each time you use StringSplit on a line in your file, you will get as many parts as there are section separated by the delimiter: "files.dat@21.12.2009@21:33" will give you 3 parts "Fred" will give you just the one as there is no delimiter present. The number of parts is held in the [0] element of the array, so you can only read that many elements - if you go over that number you get an error. So I imagine you are trying to split a line without a delimiter (@). Just check how many elements you have: $data = "files.dat@21.12.2009@21:33" $aArray = StringSplit($data , "@") $sSplits = "" For $i = 1 To $aArray[0] $sSplits &= $aArray[$i] & @CRLF Next MsgBox(0, "Split", $data & @CRLF & @CRLF & "has been split into:" & @CRLF & @CRLF & $sSplits) $data = "Fred" $aArray = StringSplit($data , "@") $sSplits = "" For $i = 1 To $aArray[0] $sSplits &= $aArray[$i] & @CRLF Next MsgBox(0, "Split", $data & @CRLF & @CRLF & "has been split into:" & @CRLF & @CRLF & $sSplits) If you are unsure about arrays, there is a very good tutorial in the Wiki. Is it clear now? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
amakrkr Posted June 18, 2010 Author Posted June 18, 2010 amakrkr, Did you read what i wrote above? As for the error: Each time you use StringSplit on a line in your file, you will get as many parts as there are section separated by the delimiter: "files.dat@21.12.2009@21:33" will give you 3 parts "Fred" will give you just the one as there is no delimiter present. The number of parts is held in the [0] element of the array, so you can only read that many elements - if you go over that number you get an error. So I imagine you are trying to split a line without a delimiter (@). Just check how many elements you have: $data = "files.dat@21.12.2009@21:33" $aArray = StringSplit($data , "@") $sSplits = "" For $i = 1 To $aArray[0] $sSplits &= $aArray[$i] & @CRLF Next MsgBox(0, "Split", $data & @CRLF & @CRLF & "has been split into:" & @CRLF & @CRLF & $sSplits) $data = "Fred" $aArray = StringSplit($data , "@") $sSplits = "" For $i = 1 To $aArray[0] $sSplits &= $aArray[$i] & @CRLF Next MsgBox(0, "Split", $data & @CRLF & @CRLF & "has been split into:" & @CRLF & @CRLF & $sSplits) If you are unsure about arrays, there is a very good tutorial in the Wiki. Is it clear now? M23 Tnank you! Now its all clear. Thanks again!
Moderators Melba23 Posted June 18, 2010 Moderators Posted June 18, 2010 amakrkr,When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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