Sign in to follow this  
Followers 0
t1ck3ts

Do loop ending itself and the GUI

3 posts in this topic

#1 ·  Posted (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 :sweating:

Edited by t1ck3ts

Share this post


Link to post
Share on other sites



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

For $I = 1 To $MBBFiles[0]
    Sleep(1000)
    GUICtrlSetData($Log," - " & $MDBFiles[$i] & @CRLF,1)
Next
No 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._______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

#3 ·  Posted (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

o:)

Heheh, thanks again!

Edited by t1ck3ts

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