Kaeft Posted October 6, 2010 Share 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. Link to comment Share on other sites More sharing options...
jaberwacky Posted October 6, 2010 Share 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? Link to comment Share on other sites More sharing options...
KaFu Posted October 6, 2010 Share 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-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) 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 (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Tvern Posted October 6, 2010 Share 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 Link to comment Share on other sites More sharing options...
Kaeft Posted October 6, 2010 Author Share 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 Link to comment Share on other sites More sharing options...
czardas Posted October 6, 2010 Share Posted October 6, 2010 If you use _ArrayAdd, it Redims the array automatically. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Tvern Posted October 6, 2010 Share 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. Link to comment Share on other sites More sharing options...
czardas Posted October 6, 2010 Share 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 Link to comment Share on other sites More sharing options...
jaberwacky Posted October 7, 2010 Share 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? 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