Jump to content
Sign in to follow this  
NoComment

ReDim Issue

Recommended Posts

NoComment

I am creating a script for work, that will clean out most viruses, but first I have to get all of the user names (to clean out temporary internet files).

Global $UserLoc = 'C:\Documents and Settings\', $WinTempLoc = 'C:\WINDOWS\Temp\', $Search, $User
Global $UserFolder[1]

$Search = FileFindFirstFile($UserLoc & '*')

While 1
    $User = FileFindNextFile($Search)
    If @error Then ExitLoop
    $UserFolder[0] += 1
    If UBound($UserFolder) <= $UserFolder[0] Then ReDim $UserFolder[UBound($UserFolder + 1)]
    $UserFolder[$UserFolder[0]] = $User
WEnd

Now, that does not work (there are 6 folders in my C:\Documents and Settings\ directory). I get this error:

C:\Documents and Settings\Chris\Desktop\Tune Up [XP]\Tune Up [XP].au3 (21) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$UserFolder[$UserFolder[0]] = $User
^ ERROR

This though, does:

Global $UserLoc = 'C:\Documents and Settings\', $WinTempLoc = 'C:\WINDOWS\Temp\', $Search, $User
Global $UserFolder[7]

$Search = FileFindFirstFile($UserLoc & '*')

While 1
    $User = FileFindNextFile($Search)
    If @error Then ExitLoop
    $UserFolder[0] += 1
    If UBound($UserFolder) <= $UserFolder[0] Then ReDim $UserFolder[UBound($UserFolder + 1)]
    $UserFolder[$UserFolder[0]] = $User
WEnd

The issue with this, is it limits it, I of course can have $UserFolder[256], but there is still that limitation, I want it to be able to expand.

Can someone help?

PS: I am aware of the _FileListToArry function, but it does not work either.

Edited by NoComment

Share this post


Link to post
Share on other sites
dantay9

Try ReDim $UserFolder[ubound($UserFolder)] or ReDim $UserFolder[ubound($UserFolder) + 1]


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
NoComment

Try ReDim $UserFolder[ubound($UserFolder)] or ReDim $UserFolder[ubound($UserFolder) + 1]

Thanks, rather than having the If statement, I put it as a standalone, and it works perfect now. Thank you.

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  

×