SeF Posted November 22, 2009 Share Posted November 22, 2009 Hello there!I'm creating a variable with a lot of content and don't know how can I extract the content from specified lines from this variable.Creating the variable:#include <IE.au3> $oIE = _IEAttach ("Receita Federal do Brasil") $oFrame = _IEFrameGetCollection ($oIE, 1) $sHTML = _IEBodyReadText ($oFrame)I've tryed using 2 different ways:FileReadToArray#include <file.au3> Dim $lines $file = FileOpen("teste.txt", 1) FileWrite($file, $sHTML) _FileReadToArray("teste.txt",$lines) MsgBox(0, "Line read:", $lines[58]) FileDelete("teste.txt")FileReadLine$file = FileOpen("teste.txt", 1) FileWrite($file, $sHTML) $file = FileOpen("teste.txt", 0) $line = FileReadLine($file, 58) MsgBox(0, "Line read:", $line) FileDelete("teste.txt")A blank file is created and while the FileWrite is doing your "job", the FileReadLine tries to read the 58 line of the file. Result: returns a blank line. The "reading line part" it's going too fast (And I'm trying to forget a little bit of 'sleep' function in this case).Can I read content from specified lines from a Variable? Or I really need to create a file to do this?Thanks! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 22, 2009 Moderators Share Posted November 22, 2009 SeF,If there is a simple delimiter as a line break (which seems likely), then you can use StringSplit directly on the variable to get the data into an array.A thought (which you have probably investigated already) - are you sure that it is line 58 you need? Sometimes the lines are not quite what you think you counted - have you looked over a range of lines in case you are reading a blank line close by?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 Link to comment Share on other sites More sharing options...
SeF Posted November 22, 2009 Author Share Posted November 22, 2009 (edited) SeF, If there is a simple delimiter as a line break (which seems likely), then you can use StringSplit directly on the variable to get the data into an array. A thought (which you have probably investigated already) - are you sure that it is line 58 you need? Sometimes the lines are not quite what you think you counted - have you looked over a range of lines in case you are reading a blank line close by? M23 Thanks for the reply M23! I usually use StringSplit a lot and tryed using it here, but didn't worked out. And yes, I'm sure that the line 58 has contents. I removed the FileDelete from my Script and it shows content. -----EDIT----- I did it! #include <IE.au3> #include <file.au3> $oIE = _IEAttach ("Receita Federal do Brasil") $oFrame = _IEFrameGetCollection ($oIE, 1) $sHTML = _IEBodyReadText($oFrame) _FileCreate(@TempDir & "test.txt") _FileWriteToLine(@TempDir & "test.txt", 1, "old") _ReplaceStringInFile(@TempDir & "test.txt", "old", $sHTML) sleep(10) $file = FileOpen(@TempDir & "test.txt", 0) $line = FileReadLine($file, 58) MsgBox(0, "Line read:", $line) File UDF is clearly faster! It's like...instantly! Edited November 22, 2009 by SeF Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 22, 2009 Moderators Share Posted November 22, 2009 SeF, I was afraid it would not be that easy! If the file is not too large, could you upload it (or provide the code which downloads it) and say which line you expect as a return. Then we can take a closer look. 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 Link to comment Share on other sites More sharing options...
SeF Posted November 22, 2009 Author Share Posted November 22, 2009 (edited) SeF,I was afraid it would not be that easy! If the file is not too large, could you upload it (or provide the code which downloads it) and say which line you expect as a return. Then we can take a closer look.M23Thanks again M23! But, I've already solved my problem.The script is working like a charm! Edited November 22, 2009 by SeF Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 22, 2009 Moderators Share Posted November 22, 2009 SeF, Would you care to say how? 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 Link to comment Share on other sites More sharing options...
SeF Posted November 22, 2009 Author Share Posted November 22, 2009 SeF, Would you care to say how? M23 I edited my 2nd post of this topic with the solution Anyway: #include <IE.au3> #include <file.au3> $oIE = _IEAttach ("Receita Federal do Brasil") $oFrame = _IEFrameGetCollection ($oIE, 1) $sHTML = _IEBodyReadText($oFrame) _FileCreate(@TempDir & "test.txt") _FileWriteToLine(@TempDir & "test.txt", 1, "old") _ReplaceStringInFile(@TempDir & "test.txt", "old", $sHTML) $file = FileOpen(@TempDir & "test.txt", 0) $line = FileReadLine($file, 58) MsgBox(0, "Line read:", $line) Still not getting the information directly from the Variable. But, I get the results quickly after all. The file itself contains about 97-109 lines. It has different number of lines depending of the case, but always with a minimum of 97 lines. A simple code like this solved this issue too: $NumLines = _FileCountLines("test.txt") $i = $Numlines - 97 Then: $line = FileReadLine($file, 58 + $i) Still getting the hang of AutoIt! 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