nf67 Posted September 15, 2009 Share Posted September 15, 2009 Hi , I just started writing a little tray launcher with a variable amount of tray menu items, but I've messed something up... (32) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded. Line #32 is the following: $Name[$i] = $Str[$i][1] I guess the next line is wrong too then, but I couldn't find the exceeding array variable, is it $Name? Or $Str? Here's the little script: #Include <Constants.au3> #include <GUIConstantsEx.au3> Opt("TrayMenuMode",1) $Settings = TrayCreateItem("Settings") $Exit = TrayCreateItem("Exit") DrawMenu() While 1 $msg = TrayGetMsg() Select Case $msg = $Exit Exit EndSelect WEnd Func DrawMenu() $Str=[3] Dim $Name[6] Dim $Path[6] Dim $MenuItem[6] For $i = 1 to 5 If FileReadLine(@ScriptDir & "\Conf.txt", $i) <> "" Then $Str[$i] = StringSplit(FileReadLine(@ScriptDir & "\Conf.txt", 1), @TAB) $Name[$i] = $Str[$i][1] ;<--- FAIL $Path[$i] = $Str[$i][2] $MenuItem[$i] = TrayCreateItem($Name[$i]) EndIf Next EndFunc Any tips on how I can let my tray menu have a variable amount of items or a fix for this method? Thanks in advance Link to comment Share on other sites More sharing options...
jvanegmond Posted September 15, 2009 Share Posted September 15, 2009 I'm not 100% sure on this but I don't think this works: $Str[$i] = StringSplit(FileReadLine(@ScriptDir & "\Conf.txt", 1), @TAB) ;<--- Actual fail (silent) $Name[$i] = $Str[$i][1] ;<--- This line errors, because $Str[$i] is not an array You need to put the result of the stringsplit into a temporary variable, then read it into $Str[$i][..] . github.com/jvanegmond Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 15, 2009 Share Posted September 15, 2009 Like Manadar said, you have bad array syntax. StringSplit() returns an entire array that you should not be trying to save to a particular index: ; Create array of strings Global $avStr[3] = ["Alpha Zero", "Beta One", "Gamma Two"] For $i = 0 To UBound($avStr) - 1 $avSplit = StringSplit($avStr[$i], " ") ; split on space $Name = $avSplit[1] $Path = $avSplit[2] ConsoleWrite("$Name = " & $Name & ", $Path = " & $Path & @LF) Next There is, technically, a way to store arrays as an element in another array. But it is bad practice in general, and the syntax still doesn't work the way you had it. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
nf67 Posted September 15, 2009 Author Share Posted September 15, 2009 (edited) Mmm so you two mean that the script won't understand that the actual array to be used is after the $Str[$i] ? I tested that and it seems to be true, as the following works fine: While 1 $msg = TrayGetMsg() Select Case $msg = $Exit Exit EndSelect WEnd Func DrawMenu() Dim $String[3] Dim $Name[6] Dim $Path[6] Dim $MenuItem[6] For $i = 1 to 5 If FileReadLine(@ScriptDir & "\Conf.txt", $i) <> "" Then $String = StringSplit(FileReadLine(@ScriptDir & "\Conf.txt", $i), @TAB) $Name[$i] = $String[1] $Path[$i] = $String[2] $MenuItem[$i] = TrayCreateItem($Name[$i]) EndIf Next EndFunc Thanks for helping out Edited September 15, 2009 by nf67 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