jennico Posted October 22, 2006 Share Posted October 22, 2006 (edited) hi, i am a little bit confused having read so much about dim and dont get it working. here`s my script designed to count and read out ini files from a plugin directory. i want to have results like this: ($file[1] = "plugin1.ini") ($file[2] = "plugin2.ini") and so on. Dim $file[22] $f=1 $pfad=0 $search = FileFindFirstFile(@ScriptDir&"\desti\Plugins\*.ini") If $search = -1 Then $pfad=1 If @error Then $pfad=1 While 1 $file = FileFindNextFile($search) If @error Then ExitLoop MsgBox(4096, $f&".File:", $file) $file[$f]=$file If $f=22 Then ExitLoop $f=$f+1 WEnd $f=$f-1 If $f > 22 Then $f=22 FileClose($search) what is wrong ? j. Error: badly formatted variable or macro line $file[$f]=$file Edited October 22, 2006 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
jennico Posted October 22, 2006 Author Share Posted October 22, 2006 none? please gimme a hint how to use the dim command correctly. j. Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
theguy0000 Posted October 22, 2006 Share Posted October 22, 2006 um it's not the dim command having the problem, it's probably the fact that you have two $file variables, one is an array, and the other a dynamic string that changes with each loop. First you have $file[22] declaring $file as an array, then you define $file = FileFindNextFile($search), defining it as a string of the filename. Then you expect $file[$f]=$file to work? it won't, because $file[22] doesn't exist anymore because you replaced it with a string. give string $file a different name than array $file[] The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
PaulIA Posted October 22, 2006 Share Posted October 22, 2006 Or in other words, something like this: Global $aFile[22] Global $iCount = 0 $hSearch = FileFindFirstFile((@ScriptDir & "\desti\Plugins\*.ini") if $hSearch = -1 then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit endif while $iCount < UBound($aFile) $sFile = FileFindNextFile($hSearch) if @Error then ExitLoop $aFile[$iCount] = $sFile $iCount = $iCount + 1 wend FileClose($hSearch) for $iI = 0 to $iCount - 1 MsgBox(4096, "File", $iI & ".File: " & $aFile[$iI]) next Auto3Lib: A library of over 1200 functions for AutoIt Link to comment Share on other sites More sharing options...
theguy0000 Posted October 22, 2006 Share Posted October 22, 2006 yeah, what he said...lol The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
jennico Posted October 22, 2006 Author Share Posted October 22, 2006 (edited) thanx for that: ", it's probably the fact that you have two $file variables, one is an array, and the other a dynamic string that changes with each loop. " i just renamed the $file, and it works Dim $ini[22] $f=1 $pfad=0 $search = FileFindFirstFile(@ScriptDir&"\desti\Plugins\*.ini") If $search = -1 Then $pfad=1 If @error Then $pfad=1 While 1 $file = FileFindNextFile($search) If @error Then ExitLoop MsgBox(4096, $f&".File:", $file) $ini[$f]=$file If $f=22 Then ExitLoop $f=$f+1 WEnd $f=$f-1 If $f > 22 Then $f=22 FileClose($search) i would have never thought that this is a problem. in my logic $file and $file(1) are different things, the one being a variable and the other an array. for autoit not. good to know. thanx a lot j. Edited October 22, 2006 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
Delai Posted March 26, 2007 Share Posted March 26, 2007 (edited) Is there any wat to declare an array without specifiy exactly the number. Global $aFile[22] ::::::> [b]Here i don´t want to put the number 22, only want to put something that depends exactly to the files founded in the following search[/b] Global $iCount = 0 $hSearch = FileFindFirstFile((@ScriptDir & "\desti\Plugins\*.ini") if $hSearch = -1 then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit endif while $iCount < UBound($aFile) $sFile = FileFindNextFile($hSearch) if @Error then ExitLoop $aFile[$iCount] = $sFile $iCount = $iCount + 1 wend FileClose($hSearch) for $iI = 0 to $iCount - 1 MsgBox(4096, "File", $iI & ".File: " & $aFile[$iI]) next Edited March 26, 2007 by Delai Link to comment Share on other sites More sharing options...
SadBunny Posted March 26, 2007 Share Posted March 26, 2007 (edited) hi, i am a little bit confused having read so much about dim and dont get it working. here`s my script designed to count and read out ini files from a plugin directory. i want to have results like this: ($file[1] = "plugin1.ini") ($file[2] = "plugin2.ini") and so on. Dim $file[22] $f=1 $pfad=0 $search = FileFindFirstFile(@ScriptDir&"\desti\Plugins\*.ini") If $search = -1 Then $pfad=1 If @error Then $pfad=1 While 1 $file = FileFindNextFile($search) If @error Then ExitLoop MsgBox(4096, $f&".File:", $file) $file[$f]=$file If $f=22 Then ExitLoop $f=$f+1 WEnd $f=$f-1 If $f > 22 Then $f=22 FileClose($search) what is wrong ? j. Error: badly formatted variable or macro line $file[$f]=$file One more thing, that you will run into after fixing the ambiguous variable names $file and $file[]: You dim $file to have 22 elements. This means they will reach from 0 to 21. Since you let the loop exit on 22 but before the loop exits, you do $file[$f]=file, you will run into the problem that the program tries to write something into element 22 which does not exist. To fix this, either dim your array one element bigger, or make the loop exit at count 21, or put the $file[$f]=file statement after the if $f=22 check. /edit: but anyway, if you know the amount of loops beforehand, I would always go for a for-next loop. It saves you the need to keep a counter and makes your code shorter and more readable. /edit 2: but I see that PaulIA already suggested that Edited March 26, 2007 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Delai Posted March 26, 2007 Share Posted March 26, 2007 My question was different because i don´t know the amount of loops before. Link to comment Share on other sites More sharing options...
MHz Posted March 26, 2007 Share Posted March 26, 2007 My question was different because i don´t know the amount of loops before.You need to set an array size and then use Redim to increase your array size. Link to comment Share on other sites More sharing options...
SadBunny Posted March 26, 2007 Share Posted March 26, 2007 My question was different because i don´t know the amount of loops before.That's why I replied to jennico and not to you As for your question, you can do for instance Dim $array[1] or Dim $array and later use ReDim to add extra element slots to the array. Roses are FF0000, violets are 0000FF... All my base are belong to you. 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