Jump to content
Sign in to follow this  
aommaster

Two snippets, one works and one doesn't

Recommended Posts

aommaster

Below are two snippets of code, both of which (I believe) should achieve the same thing.

#Include <File.au3>
#include <array.au3>

$folderarray = _FileListToArray("bgm/", "*", 2)
for $folder in $folderarray
    $filelist = _filelisttoarray("bgm/"& $folder, "*.mp3", 1)
    
    for $i=1 to ubound($filelist)-1
        msgbox(0,0, $fileitem)
    Next
Next

And this is the other:

#Include <File.au3>
#include <array.au3>

$folderarray = _FileListToArray("bgm/", "*", 2)
for $folder in $folderarray
    $filelist = _filelisttoarray("bgm/"& $folder, "*.mp3", 1)
    
    for $fileitem in $filelist
        msgbox(0,0, $fileitem)
    Next
Next

However, the second snippet doesn't work. Autoit gives me an error:

Variable must be of type "Object"

for the second nested For..in loop.

What is the reason for this?

Share this post


Link to post
Share on other sites
Beege

For In statment is for object collections.

Ya scratch that.. Its for arrays too.

Edited by Beege

Share this post


Link to post
Share on other sites
picaxe

However, the second snippet doesn't work. Autoit gives me an error:

Variable must be of type "Object"

for the second nested For..in loop.

What is the reason for this?

You can read but not update/create an array inside a For In Next statement. Edited by picaxe

Share this post


Link to post
Share on other sites
aommaster

You can read but not update/create an array inside a For In Next statement.

Oh, I see. So I'm assuming I can't have this line in the for..in loop?

$filelist = _filelisttoarray("bgm/"& $folder, "*.mp3", 1)

Thanks

Share this post


Link to post
Share on other sites
picaxe

The problem is reusing the array $filelist in a For In Next statement, because of the read only limitation. Whereas For To Next is Ok.

Edited by picaxe

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.