Wingens Posted March 14, 2015 Share Posted March 14, 2015 Hi, i have problem, i started using an array for checking files in a folder and adding them to a combobox. But if the folder is empty then my script crashes, i tried to check the array with: $NAME = GUICtrlRead($AFDELINGLIST) $VAR = IniRead("P:\Afdelingen\afdelingen.ini", "names", $NAME, "") GUICtrlSetState($SOFTWARE, $GUI_ENABLE) GUICtrlSetData($SOFTWARE, "") GUICtrlSetData($SOFTWARE, "Geen installatie bestanden") GUICtrlSetData($SOFTWARE, "================================================") Local $FileList = _FileListToArray("P:\Software\Afdelingen\" & $VAR & "\", "*.*", $FLTA_FILES) For $i = 1 To $FileList[0] If $i <> "" Then GUICtrlSetData($SOFTWARE, $FileList[$i]) EndIf Next But when i run my script and i get to the point where it reads the ini file (checked the values comming from that with msgbox, they are good), after that it should go to the array but then it crashes if the folder is empty, if i add a file the array works. How can i catch this error? Link to comment Share on other sites More sharing options...
Solution LarsJ Posted March 14, 2015 Solution Share Posted March 14, 2015 Click _FileListToArray in the code box and read. Especially about failure and @error in the "Return Value"-section. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
DocTorCoder Posted March 14, 2015 Share Posted March 14, 2015 (edited) Try this: This "If $i <> "" Then" is useless because you start with $i with value 1 (That for). So that check is useless because it always happen this way! Local $FileList = _FileListToArray("P:\Software\Afdelingen\" & $VAR & "\", "*.*", $FLTA_FILES) If ($FileList[0] <> 0) Then For $i = 1 To $FileList[0] GUICtrlSetData($SOFTWARE, $FileList[$i]) Next EndIf Read this too: https://www.autoitscript.com/autoit3/docs/libfunctions/_FileListToArray.htm Edited March 14, 2015 by DocTorCoder DocTorCoder Link to comment Share on other sites More sharing options...
LarsJ Posted March 14, 2015 Share Posted March 14, 2015 DocTorCoder, What do you think happens if the folder is empty and $FileList is not an array? Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Wingens Posted March 14, 2015 Author Share Posted March 14, 2015 damn, i was thinking to difficult. thanks! Link to comment Share on other sites More sharing options...
DocTorCoder Posted March 14, 2015 Share Posted March 14, 2015 (edited) DocTorCoder, What do you think happens if the folder is empty and $FileList is not an array? Nothing,Filelist will be empty,so size "0" and will not enter in for. I am missing something? Or maybe will return "4 - No File(s) Found" ? Didnt test it . I just think of what would happened! Edited March 14, 2015 by DocTorCoder DocTorCoder 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