DerPensionist Posted June 19, 2014 Share Posted June 19, 2014 _FileReadToArray delets targetarray if FileReaf fails. This is new in Autoit 3.3.12.0 an seems to be an error. If $FRTA_COUNT=on(default) should @error set and existing $array[0] set to 0. simple code like this: {{{ #include <file.au3> Global $aSEN[1] ; SendungsTabelle: Beg(Datum,Uhrzeit),End(Datum Uhrzeit),Kanal,Titel,Bemerkungen... Global $uSEN=Ubound(SEN,1) ;---------------- Channel-Tabelle Global $fSEN = @ScriptName & ".CSV" ; Sendungs-Datei If Not _FileReadToArray($fSEN, $aSEN,$FRTA_COUNT ) Then ;MsgBox(4096, "Error", " Fehler lesen SEN-Datei error:" & @error) ReDim $aSEN[1] ;result 3.3.12.0 ==> "ReDim" used without an array variable.: $aSEN[1] = "1900/01/01 00:00" EndIf $uSEN = UBound($aSEN, 1) }}} worked fine till the new version. Is this a bug ? Link to comment Share on other sites More sharing options...
BrewManNH Posted June 19, 2014 Share Posted June 19, 2014 Yes, that's new in this latest version. The array is converted to a simple variable, and then if no files are found, that variable is returned. The older version didn't even require an array to be sent to it, and neither does this one, they both will accept a simple variable. 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...
DerPensionist Posted June 19, 2014 Author Share Posted June 19, 2014 Sorry, bug of mine or UDF? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 19, 2014 Moderators Share Posted June 19, 2014 DerPensionist,It fails because you are not using the correct function to re-declare your array. If _FileReadToArray fails, you do not get an array returned - and why should you as there is no data to fill it? So using ReDim will not work as you are attempting to resize a variable which is no longer an array. It only worked before by chance. What you should do is re-declare the array properly using Global - and then you need to address the single element correctly as AutoIt arrays begin at 0, not 1:#include <file.au3> Global $aSEN[1] ; SendungsTabelle: Beg(Datum,Uhrzeit),End(Datum Uhrzeit),Kanal,Titel,Bemerkungen... Global $uSEN = UBound($aSEN, 1) ConsoleWrite($uSEN & @CRLF) ;---------------- Channel-Tabelle Global $fSEN = @ScriptName & ".CSV" ; Sendungs-Datei If Not _FileReadToArray($fSEN, $aSEN, $FRTA_COUNT) Then ConsoleWrite(VarGetType($aSEN) & @CRLF) ; This is now an Int32 as there is no array to return ;MsgBox(4096, "Error", " Fehler lesen SEN-Datei error:" & @error) Global $aSEN[1] ; Re-declare the array correctly... <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $aSEN[0] = "1900/01/01 00:00" ; ...and address the element correctly as well <<<<<<<<<<<<<<<<<<<<<<<<< EndIf $uSEN = UBound($aSEN, 1) ConsoleWrite($uSEN & @CRLF)All clear? 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...
DerPensionist Posted June 19, 2014 Author Share Posted June 19, 2014 not yet. Why destroy _FileReadToArray my global defined array, and changes it to string? I can't find anything about returning a string in the dokumentation. On the otherhand it worked erarlier incorrect? But anyway, this is the result of missing empty arrays and returning strings instead. (p.s. the 0/1 problem was only by preparing the sample.) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 20, 2014 Moderators Share Posted June 20, 2014 (edited) DerPensionist,The answer to all 3 questions is that it the result of a design decision made when the _FileReadToArray function was rewritten for v3.3.12.0 - the variable passed ByRef is converted to a string if an error occurs. If nothing is specified as a return value in the documentation then you cannot expect any particular datatype to be returned -and indeed why should you expect your variable to remain an array if there is nothing to put in it? Besides, if you are expecting an array as a return from a function, you should always check that you indeed have an array, particularly after an error - many of the functions which could return arrays return strings in the case of an error, so this change actually reflects wider AutoIt behaviour. Originally we were going to amend the function to return an array directly like most of the other _File* functions rather then using a variable passed ByRef - it took direct intervention from Jon to prevent us from doing this. And as I explained above, you should use Global/Local to re-declare an array, not ReDim - the fact it worked before was only because if the variable was an array it remained so after an error when there was no reason for it to do so. So I am afraid I have little sympathy with your complaints. It was pure chance that the code you used worked before - had you coded correctly in the first place than you would have not had this problem. None of my code using this function needed any modification after the change in _FileReadToArray. M23P.S. AutoIt has featured empty arrays since v3.3.10.0 - please read the changelogs we provide. Edited June 22, 2014 by Melba23 Reworded to make clear the variable passed ByRef does not have to be an array 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...
DerPensionist Posted June 21, 2014 Author Share Posted June 21, 2014 Behaviour of Autoit seems for me in this case a bit strange. When the UDF expects an array, specialy using ByRef, then means for me the array would be updatet, even there is nothing to update. But anyway, accepted. p.s.: I red changelog: "Added: Empty arrays." was not so meaningfull. So I looked in "#include <array.au3>" and the second function seems to return inorrect values if "emty array" is input: Dim $aArray[0] ConsoleWrite(@cr & "==> @error:" &@error & @TAB & "Result:'" & $rc & "'" & @cr) ==> @error:3 Result:'-1' expected : ==> @error:0 Result:'' Link to comment Share on other sites More sharing options...
guinness Posted June 21, 2014 Share Posted June 21, 2014 In this instance ByRef acts like out does in C#. Behaviour of Autoit seems for me in this case a bit strange. When the UDF expects an array, specialy using ByRef, then means for me the array would be updatet, even there is nothing to update You're passing a variable to store whatever the functions spits out at you, not an existing array. I don't know where you came to that conclusion. If it asked for an existing array then documentation would state so. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
DerPensionist Posted June 21, 2014 Author Share Posted June 21, 2014 I passed an "empty array" and NOT a string varable. Link to comment Share on other sites More sharing options...
Solution czardas Posted June 21, 2014 Solution Share Posted June 21, 2014 It's pretty easy to make your own _FileReadToArray() using FileRead() and String functions. Then you can control exactly how errors/return values are handled to suit whatever purpose you desire. Many UDF functions are created to fulfil general requirements and are not suited to specific purposes. I understand your way of thinking - empty arrays are a recent addition to AutoIt. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 22, 2014 Moderators Share Posted June 22, 2014 DerPensionist,I may have misled you earlier when I said:the array passed ByRef is converted to a string if an error occursIn fact you need pass only a variable name - it does not have to be an array at all - which is then manipulated ByRef in the function. If the function completes successfully, the variable will be an array - if not, a string. But my advice still remains as before - code correctly for error cases when using functions which may or may not produce an array and you will have no 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 June 22, 2014 Share Posted June 22, 2014 The help file needs to be changed, because the description of the second parameter for _FileReadToArray states it should be an array that is passed to the function. $aArray Array to hold returned data 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...
Moderators Melba23 Posted June 22, 2014 Moderators Share Posted June 22, 2014 BrewManNH,Done. 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...
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