t1ck3ts Posted July 17, 2014 Share Posted July 17, 2014 (edited) I have a function in my GUI that runs on start Func MDBList() Local $MDBFiles = _FileListToArray(@ScriptDir, "*.mdb", $FLTA_FILES) Local $i = 1 Do Sleep(1000) GUICtrlSetData($Log," - " & $MDBFiles[$i] & @CRLF,1) $i = $i + 1 Until $i = $MDBFiles[0 + 1] EndFunc While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd but when it ends, it also ends the GUI, which is not what i want From reading Melba23's post in the Wiki (http://www.autoitscript.com/wiki/Interrupting_a_running_function), I think im using a GUI in MessageLoop mode but im not 100% sure how to go about it as it uses buttons being pressed and i have my code run at start up. Any way around this? EDIT:It seems to be _FileListToArray is the culprit, a simple Do loop works perfectly. After throwing in some error checking, i get this : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: GUICtrlSetData($Log," - " & $MDBFiles[$i] & @CRLF,1) GUICtrlSetData($Log," - " & ^ ERROR From what i can tell, its because i did Until $i = $MDBFiles[0 + 1] But i dont know how i would make it display all *.mdb files, [0] is the ammount of files it found $i = 1 is to read the first file in the list. EDIT #2: Why is it when ever i ask a question on the forums, it makes me realise where my mistake was /facepalm Func MDBList() Local $MDBFiles = _FileListToArray(@ScriptDir, "*.mdb", $FLTA_FILES) Local $i = 0 Do Sleep(1000) $i = $i + 1 GUICtrlSetData($Log," - " & $MDBFiles[$i] & @CRLF,1) Until $i = $MDBFiles[0] EndFunc Is the working code Edited July 17, 2014 by t1ck3ts Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted July 17, 2014 Moderators Solution Share Posted July 17, 2014 t1ck3ts,You are using MessageLoop mode - or I should say you are using GUIGetMsg which normally means that you are. You have a major flaw in the code which will probably crash the script - that would close your GUI:Until $i = $MDBFiles[0 + 1]Do you really want to wait until $I is the same as the first returned filename - because it will never happen and you will try to read a non-existent array element and crash. The line should read:Until $i = $MDBFiles[0]But why use a Do loop anyway: For $I = 1 To $MBBFiles[0] Sleep(1000) GUICtrlSetData($Log," - " & $MDBFiles[$i] & @CRLF,1) NextNo messy counts then. But I would recommend a check that you actually have an array before trying to access it. 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...
t1ck3ts Posted July 17, 2014 Author Share Posted July 17, 2014 (edited) hahaha, thanks Melba23 It always happens to me when i post something on the forums, take a look at my post, and then realise, "God damn it! you're an idiot!" Everything you said, is exactly what i changed And after taking ANOTHER look at your wiki post, i actually used a a For loop as you have just said So much more simpler too! For $I = 1 To $MBBFiles[0] Sleep(1000) GUICtrlSetData($Log," - " & $MDBFiles[$i] & @CRLF,1) Next I dont have an array for $MBBFiles but i do for $MDBFiles Heheh, thanks again! Edited July 17, 2014 by t1ck3ts 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