Surviver Posted December 9, 2010 Share Posted December 9, 2010 (edited) I have this script, and the problem is that _FileWriteFromArray doesn't write both groups of arrays, but just one of them.Here is the script: #include <String.au3> #include <Array.au3> #include <File.au3> $sMainUrl = "http://www.filmulde10.com/load/rss" $sGetInfo = BinaryToString(InetRead($sMainUrl)) $sCorectText = StringReplace($sGetInfo, "'", "'") $aTitle = _StringBetween($sCorectText, "<title>", "</title>") $aCategory = _StringBetween($sCorectText, "<category>", "</category>") _FileWriteFromArray("OutputResult.txt",$aCategory & @Tab & @Tab & $aTitle) If Not @error Then MsgBox(0, '', 'OK!') Else MsgBox(0, '', 'Error: ' & @error) EndIf ShellExecute("OutputResult.txt") Edited December 10, 2010 by Surviver Link to comment Share on other sites More sharing options...
iamtheky Posted December 9, 2010 Share Posted December 9, 2010 (edited) is it the 2nd one every time?If a string path is provided, the file is overwritten and closed.To use other write modes, like append or Unicode formats, open the file with FileOpen() first and pass the file handle instead. Edited December 10, 2010 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted December 10, 2010 Share Posted December 10, 2010 @Surviver $aCategory is an array. $aCategory & @Tab & òTab & $aTitle is one array, two tabs (i assume ò is a spelling error) and another array. The problem should be obvious. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Surviver Posted December 10, 2010 Author Share Posted December 10, 2010 Yes, that should be two tabs, I have wrong spelled, my fault.Now, I still didn't get how to solve the problem... Link to comment Share on other sites More sharing options...
BrewManNH Posted December 10, 2010 Share Posted December 10, 2010 You're trying to write two arrays at the same time, and the function won't handle that, it's not designed to write more than one array at a time. You need to use 2 different filewritefromarray lines to accomplish what you want to do. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Surviver Posted December 11, 2010 Author Share Posted December 11, 2010 (edited) Yes, but if I use 2 different _FileWriteFromArray, then the second aray will be written UNDER the first array, and I do not want that... I wish to sync the elements of the first array with the elements of the second array, like: Array_1[0] & @TAB & @TAB & Array_2[0] Array_1[1] & @TAB & @TAB & Array_2[1] Array_1[2] & @TAB & @TAB & Array_2[2] and so on... Edited December 11, 2010 by Surviver Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 11, 2010 Moderators Share Posted December 11, 2010 Surviver,I wish to sync the elements of the first array with the elements of the second arrayThen you will have to develop your own version of the _FileWriteFromArray UDF. Looking at the original code, it should not be hard to get it to do what you want - why not give it a go yourself? You know where we are if you run into problems. 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...
BrewManNH Posted December 11, 2010 Share Posted December 11, 2010 Use a third array to hold the elements in the order that you want them in, or don't use FileWriteFromArray. You can do it easily with a For...Next loop and a FileWriteLine statement, and just loop through both arrays and write them to the file as you go through it. Also, unless both arrays are the exact same size, i.e. the same number of dimensions and subscripts, you're going to get an error as you loop through them. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Surviver Posted December 12, 2010 Author Share Posted December 12, 2010 Well I did wrote my own UDF, a combo of FileOpen, FileWrite, FileClose and _FileWriteFromrray and I partially solved the problem. Now I show the code of UDF, then I'll tell the rest. expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name...........: _OutputResult ; Description ...: Write the gathered data to a file. ; Syntax.........: _OutputResult(($File, $vData, $iMode = 2, $i_Base = 0, $i_UBound = 0 ) ; Parameters ....: $hFile - Name of the file to write ; $vData - The text/data to write to the file. ; $iMode - Mode to open the file in. ; |Can be a combination of the following: ; | 0 = Read mode ; | 1 = Write mode (append to end of file) ; | 2 = Write mode (erase previous contents) [DEFAULT] ; | 8 = Create directory structure if it doesn't exist (See Remarks). ; | 16 = Force binary mode (See Remarks). ; | 32 = Use Unicode UTF16 Little Endian reading and writing mode. Reading does not override existing BOM. ; | 64 = Use Unicode UTF16 Big Endian reading and writing mode. Reading does not override existing BOM. ; | 128 = Use Unicode UTF8 (with BOM) reading and writing mode. Reading does not override existing BOM. ; | 256 = Use Unicode UTF8 (without BOM) reading and writing mode. ; | 16384 = When opening for reading and no BOM is present, use full file UTF8 detection. If this is not used then only the initial part of the file is checked for UTF8. ; The folder path must already exist (except using mode '8' - See Remarks). ; $i_Base - [optional] Start Array index to read, normally set to 0 or 1. Default=0 ; $i_UBound . [optional] Set to the last record you want to write to the File. default=0 - whole array. ; Return values .: Success - A file containing the text/data. ; Failure - A blank file. ; Author ........: Simion Roberto Marius ( RisingACK ) ; Modified.......: ; Remarks .......: If a string path is provided, the file is overwritten and closed (depends on the mode of opening file, see $iMode). ; If the Data is an array, it will be written to the file (0 Index based array) ; Related .......: FileOpen, Filewrite, FileClose ; Link ..........: ; Example .......: yes ; _OutputResult("FileTest.txt",1,"Test Is done !") ; =============================================================================================================================== Func _OutputResult($File, $vData,$iMode = 2, $i_Base = 0, $i_UBound = 0 ) Local $sFileOpen = "OutputResult.txt" Local $iFileMode = 2 Local $iFileWrite Local $hFileClose If $File = "" Then $File = $sFileOpen EndIf If $iMode = -1 Then $iMode = $iFileMode EndIf $hFileOpened = FileOpen($File, $iMode) If IsArray($vData) Then Local $i_Last = UBound($vData) - 1 If $i_UBound < 1 Or $i_UBound > $i_Last Then $i_UBound = $i_Last If $i_Base < 0 Or $i_Base > $i_Last Then $i_Base = 0 For $x = $i_Base To $i_UBound $hFileWrite = FileWrite($hFileOpened, $vData[$x] & @CRLF) Next Else $hFileWrite = FileWrite($hFileOpened, $vData) EndIf $hFileClose = FileClose($hFileOpened) EndFunc ;==>_OutputResult Now, this is my first UDF, so the name of variables could be not the good ones, but you can help me. So, as you can see, this function gather the data and put it onto a file, no matter if is array or just text. I use it in script and function, for example #include <String.au3> ;~ #include <Array.au3> ;~ #include <File.au3> #include "../UDF/_OutputResult.au3" $sMainUrl = "http://www.filmulde10.com/load/rss" $sGetInfo = BinaryToString(InetRead($sMainUrl)) $sCorectText = StringReplace($sGetInfo, "'", "'") $aTitle = _StringBetween($sCorectText, "<title>", "</title>") $aCategory = _StringBetween($sCorectText, "<category>", "</category>") _OutputResult("",$aCategory[0] & @TAB & @TAB & $aTitle[0]) If Not @error Then MsgBox(0, '', 'OK!') Else MsgBox(0, '', 'Error: ' & @error) EndIf ShellExecute("OutputResult.txt") But if I use _OutputResult("",$Category & @TAB & @TAB & $Title) the problem with the first array written but the second not, is coming back... About the _OutputResult UDF: I would be glad to hear something about it. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 12, 2010 Moderators Share Posted December 12, 2010 Surviver, the problem with the first array written but the second not, is coming back...And I am not surprised. You have already been told that you cannot combine complete arrays by using the & operator - you can only use that on the individual elements of arrays. So you need a loop where you write each element of the array in turn: For $i = 0 To UBound($aCategory) - 1 _OutputResult("", $aCategory[$i] & @TAB & @TAB & $aTitle[$i] & @CRLF, 1) Next A couple of things to note: - 1. You use the $i variable to address the individual elements of the arrays. - 2. You need to add a @CRLF at the end of the line, FileWrite does not do that for you. - 3. You must use Mode 1 or you will continually overwrite the file - so you need to make sure that any exisiting file is deleted before you start the loop. As to the function, I have a few comments: Func _OutputResult($File, $vData, $iMode = 2, $i_Base = 0, $i_UBound = 0 ) ;Local $sFileOpen = "OutputResult.txt" ; Do not mix filenames and handles <<<<<<<<<<<<<<<<<<<<<<<<<<< ;Local $iFileMode = 2 ; You never use this <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $iFileWrite ;Local $hFileClose ; No need for this <<<<<<<<<<<<<<<<<<<<<<<<<<<<< If $File = "" Then $File = "OutputResult.txt" EndIf ;If $iMode = -1 Then ; What were you trying to do here? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; $iMode = $iFileMode ;EndIf $hFileOpened = FileOpen($File, $iMode) If IsArray($vData) Then Local $i_Last = UBound($vData) - 1 If $i_UBound < 1 Or $i_UBound > $i_Last Then $i_UBound = $i_Last If $i_Base < 0 Or $i_Base > $i_Last Then $i_Base = 0 For $x = $i_Base To $i_UBound $hFileWrite = FileWrite($hFileOpened, $vData[$x] & @CRLF) Next Else $hFileWrite = FileWrite($hFileOpened, $vData) EndIf FileClose($hFileOpened) EndFunc ;==>_OutputResult I hope everything is clear - if not, please ask. 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...
Surviver Posted December 12, 2010 Author Share Posted December 12, 2010 (edited) Thank you for help and fixing my UDF, and yes, I have the answer for the UDF questions made by you. Q by you: ;If $iMode = -1 Then ; What were you trying to do here? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; $iMode = $iFileMode ;EndIf A by me: If the user want to get the data of an array and to start from the index that he wish, instead of typing the mode (for example he want the default), he pass -1. Ex:_OutputResult("",$Array,-1,3,9). I don't know how can I make it to let the user just type _OutputResult("",$Array,,3,9) (note that -1 has gone). Edited December 12, 2010 by Surviver Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 12, 2010 Moderators Share Posted December 12, 2010 Surviver,If you have optional parameters you must fill all of them that precede the final one used. So you cannot use_OutputResult("",$Array,,3,9)And if you amend those lines I commented out to read like this:If $iMode = -1 Then $iMode = 2 EndIfwhich will let you use this syntax:_OutputResult("",$Array,-1,3,9)you ask the user to type 2 characters in place of 1. So I think it best to leave the user to fill in the mode required if the final parameters are used. 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...
GEOSoft Posted December 12, 2010 Share Posted December 12, 2010 You could add the line If $iMode = "" OR StringRegExp($iMode, "(?i)-1|default") Then $iMode = 2 This would also probably work If NOT StringRegExp($iMode, "^[01]$") Then $iMode = 2 Use either as the first line in the function George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Surviver Posted December 12, 2010 Author Share Posted December 12, 2010 (edited) you ask the user to type 2 characters in place of 1. So I think it best to leave the user to fill in the mode required if the final parameters are used. M23Wow, that show me how inattentive to details I am...You're so right..@GEOSoft: Thanks, I will not add that line,first because is not working (I mean it can't be left blank wich were my intentions), and second because Melba is right, I must leave the user to fill the mode. Edited December 12, 2010 by Surviver Link to comment Share on other sites More sharing options...
GEOSoft Posted December 12, 2010 Share Posted December 12, 2010 (edited) Melba is always right but the line I gave you would not allow it to be left blank. If it was not either 0 or 1 then it would default to 2 EDIT: I just tested the second one I gave you and for sure that works Edited December 12, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 12, 2010 Moderators Share Posted December 12, 2010 George,Melba is always rightI think I will frame this one! And bookmark it so I can point you back to it from time to time! 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...
GEOSoft Posted December 12, 2010 Share Posted December 12, 2010 I should have addedin other peoples eyes.You know where you stand in my eyes. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 12, 2010 Moderators Share Posted December 12, 2010 George,You know where you stand in my eyesAbsolutely - you have told me often enough! 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...
GEOSoft Posted December 12, 2010 Share Posted December 12, 2010 Remember that fella and don't try to step on my toes again. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" 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