Sign in to follow this  
Followers 0
DerPensionist

_FileReadToArray delets targetarray since Autoit 3.3.12.0

13 posts in this topic

_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 ?

Share this post


Link to post
Share on other sites



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 Gude
How 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

Share this post


Link to post
Share on other sites

Sorry, bug of mine or UDF?

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

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.)

Share this post


Link to post
Share on other sites

#6 ·  Posted (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? :huh:

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. :)

M23

P.S. AutoIt has featured empty arrays since v3.3.10.0 - please read the changelogs we provide. ;)

Edited 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

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:''

Share this post


Link to post
Share on other sites

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.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

I passed an "empty array"  and NOT a string varable.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

DerPensionist,

I may have misled you earlier when I said:

the array passed ByRef is converted to a string if an error occurs

In 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

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 Gude
How 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

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0