Sign in to follow this  
Followers 0
possmkngdm

growing array

12 posts in this topic

Intention: search files in a directory and add to array

; search for users

FileChangeDir($userDir)

$search = FileFindFirstFile("*.ini")

If $search = -1 Then

MsgBox(0, "Error", "No user files found")

Exit

EndIf

; get list of user ini files

Dim $userList[1]

$i = 0

While 1

ReDim $userList[$i + 1]

$user = FileFindNextFile($search)

If @error Then ExitLoop

$userList[$i] = $user

WEnd

$userList ends up with just the last found filename :/

Share this post


Link to post
Share on other sites



maybe more like this

Dim $userList, $i = 0, $userDir

; search for users
FileChangeDir($userDir)
$search = FileFindFirstFile("*.ini")
If $search = -1 Then
    MsgBox(0, "Error", "No user files found")
    Exit
EndIf

; get list of user ini files

for $i = 1 to 1000
    $user = FileFindNextFile($search)
    If @error Then ExitLoop
    $userList[$i] = $user
    MsgBox(0,"user", $userList[$i])
Next

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

hmm...keep getting

$userList[$i] = $user

$userList^ ERROR

Error: Expected a "=" operator in assignment statement.

(got same error trying to get my code with the while loop to work as well)

Edited by possmkngdm

Share this post


Link to post
Share on other sites

try this...replace this

Dim $userList, $i = 0, $userDir

with this

Dim $userList[100], $i = 0, $userDir

i can't actually test this... ok

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

ah, thanks, thought I already tried that, but tried it again and it worked

only issue is that the array doesn't actually grow (which I was aiming for), the resulting array gets padded to fill the initialized size if there are less elements

Edited by possmkngdm

Share this post


Link to post
Share on other sites

ah, thanks, thought I already tried that, but tried it again and it worked

only issue is that the array doesn't actually grow (which I was aiming for), the resulting array gets padded to fill the initialized size if there are less elements

<{POST_SNAPBACK}>

not sure i understand... but maybe this????

Dim $userList[100], $i = 0, $userDir, $usertotal

; search for users
FileChangeDir($userDir)
$search = FileFindFirstFile("*.ini")
If $search = -1 Then
    MsgBox(0, "Error", "No user files found")
    Exit
EndIf

; get list of user ini files

for $i = 1 to 1000
    $user = FileFindNextFile($search)
    If @error Then ExitLoop
    $userList[$i] = $user
    $usertotal = $usertotal & "num " & $i & "   " & $userList[$i] & @CRLF
    MsgBox(0,"user", $userList[$i])
Next    
MsgBox(0,"user", $usertotal)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

ah, that's the trick, thanks a lot!!! :whistle:

Share this post


Link to post
Share on other sites

please post a pic of your last message box.... ok

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

not exactly sure how you would post a pic here, but if you want, I can post it to my website...let me know

Share this post


Link to post
Share on other sites

not exactly sure how you would post a pic here, but if you want, I can post it to my website...let me know

<{POST_SNAPBACK}>

when you open the screen to create a post ( where i am typing right now)

at the bottom there is a "Browse" button

then the "attach" button ( after it uploads)

ok?

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

here you, thanks again!

Share this post


Link to post
Share on other sites

here you, thanks again!

<{POST_SNAPBACK}>

Cool... Cool... Cool...

Just like I imagined while I was writting in the dark ( not able to test it)

Enjoy!

8)


NEWHeader1.png

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