Kaeft 0 Posted October 6, 2010 Basically I'm trying to find an easy way to make a check to an array. I'll let the code do more of the talking. You will see what I mean after you see the code. Func votekick($name) $ircname = "Computer" $l = 0 $looparray = UBound($votearray,2) while $l <= $looparray if $votearray[$l][0] = $name Then $votearray[$l][1] += 1 $t = $looparray if $votearray[$l][1] >= 3 Then _ArrayDisplay($votearray) MsgBox(0,"yoik", $name & " is being a bum! going to kick when it gets implimented!") _IRC_SendPrivateMessage("kick " & $name,$ircname) EndIf Else If $t = $looparray Then $votearray[0][0] = $name $votearray[0][1] = 1 Else $t += 1 EndIf EndIf WEnd EndFunc Error: ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: if $votearray[$l][0] = $name Then if ^ ERROR I want this to search through the array from $votearray[0][1] to $votearray[end of the array][1]. Which is basically just a column of names through the array. If it can't find the name then it adds it. Share this post Link to post Share on other sites
jaberwacky 327 Posted October 6, 2010 (edited) An off by one error $looparray = UBound($votearray,2) --> $looparray = UBound($votearray,2) - 1 Edited October 6, 2010 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Share this post Link to post Share on other sites
KaFu 295 Posted October 6, 2010 Is $votearray defined as a global array? Additionally $l is not enumerated and always 0. Maybe try something like this: Func votekick($name) $ircname = "Computer" For $i = 0 To UBound($votearray) - 1 If $votearray[$i][0] = $name Then $votearray[$i][1] += 1 If $votearray[$l][1] >= 3 Then _ArrayDisplay($votearray) MsgBox(0, "yoik", $name & " is being a bum! going to kick when it gets implimented!") _IRC_SendPrivateMessage("kick " & $name, $ircname) ExitLoop EndIf EndIf Next EndFunc ;==>votekick OS: Win10-1909 - 64bit - German, AutoIt Version: 3.3.14.5, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2019-Dec-21) BIC - Batch-Image-Cropper (2019-Dec-11) COP - Color Picker (2009-May-21) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2019-Dec-07) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Share this post Link to post Share on other sites
Tvern 11 Posted October 6, 2010 I'll let the code do more of the talking. I think your code speaks a different dialect. I had some trouble figuring out exactly what you wanted to do and had to make some assumptions. Here is what I think it's meant to do. I think the main problem was the one Jaberwocky pointed out, but ran into some issues where your code contradicted itsself. expandcollapse popup#include <array.au3> Global $votearray[4][2] = [["Paul",0],["Jim",0],["Richard",0],["Louis",0]] ;I assume $votearray would look something like this ;just made a gui to test the function with. #region GUI Local $aCtrlButton[UBound($votearray)] Local $msg GUICreate("testgui") For $i = 0 To UBound($aCtrlButton) -1 $aCtrlButton[$i] = GUICtrlCreateButton($votearray[$i][0],10,10+($i*25),100,20) Next GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case 0 ContinueLoop Case -3 Exit EndSwitch For $i = 0 To UBound($aCtrlButton) -1 If $msg = $aCtrlButton[$i] Then votekick($votearray[$i][0]) _ArrayDisplay($votearray) ContinueLoop 2 EndIf Next WEnd #endregion Func votekick($name) Local $ircname = "Computer" ;you where counting the "collumns", while the rest of the script indicates you need to count "rows" ;For loops are made of win when working with arrays. Keep in mind that the last index = "arraysize"-1 (if the array has 18 indices, the last one is 17) For $l = 0 To UBound($votearray)-1 If $votearray[$l][0] = $name Then ;found the matching name If $votearray[$l][1] < 2 Then ;if that name doesn't have to many votes yet... $votearray[$l][1] += 1 ;increase his votes by 1 Else MsgBox(0,"yoik", $name & " is being a bum! going to kick when it gets implimented!") _IRC_SendPrivateMessage("kick " & $name,$ircname) $votearray[$l][1] = 0 ;reset his votes ;you might prefer to _ArrayDelete() that row here (my example GUI would break) EndIf Return ;at this point there is no reason to continue the loop, unless the same name may occur twice EndIf Next EndFunc Share this post Link to post Share on other sites
Kaeft 0 Posted October 6, 2010 (edited) You guys are the bomb. I don't care what the [insert higher power here] says. The array is going to be dynamic. Basically if the function is called with a name. It checks for the name, if the name doesn't exists then it adds it to the array. Right now the array is dimed as $votearray[1][5]. If I need to add another row would I have to redim it? Edited October 6, 2010 by Kaeft Share this post Link to post Share on other sites
czardas 1,269 Posted October 6, 2010 If you use _ArrayAdd, it Redims the array automatically. operator64 ArrayWorkshop Share this post Link to post Share on other sites
Tvern 11 Posted October 6, 2010 The array is going to be dynamic. I got that, but it's always going to have the name in collumn0, and the votes in collumn1 right? If I need to add another row would I have to redim it? Yes, unless you give the array a fixed size that is always going to be large enough to hold all entries. ReDim $votearray[UBound($votearray)+1][UBound($votearray,2)] ;add a row ReDim $votearray[UBound($votearray)][UBound($votearray,2)+1] ;add a collumn P.S. As far as I know _ArrayAdd can only write to collumn0, so it's benefits are kind of lost on multi dimension arrays. Share this post Link to post Share on other sites
czardas 1,269 Posted October 6, 2010 (edited) P.S. As far as I know _ArrayAdd can only write to collumn0, so it's benefits are kind of lost on multi dimension arrays.Yeah, I just woke up. I sometimes forget which functions have that limitation. Sorry. Edited October 6, 2010 by czardas operator64 ArrayWorkshop Share this post Link to post Share on other sites
jaberwacky 327 Posted October 7, 2010 You guys are the bomb. I don't care what the [insert higher power here] says. **Checks under desk for hidden microphone!** Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Share this post Link to post Share on other sites