Hypertrophy Posted June 22, 2009 Share Posted June 22, 2009 (edited) Please help me solve problem in my code. Or maybe another way to handle the events in For loop without using a Switch statement. It's not runnable but basically shows the structure of my main code and how things work. I am getting an error on line 22 SAYING "SUBSCRIPT USED WITH NON-ARRAY VARIABLE". Is there anything wrong with this code?#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Constants.au3> $gui = GUICreate("", 400, 400) $button = GUICtrlCreateButton("", 50, 50, 50, 20) GUISetState() While 1 $msg = GUIGetMsg(1) Switch $msg[1] Case $button msgbox(0, "", "whatever") EndSwitch ; loop for handling separate events For $i = 1 To $ahInput[0][0] Switch $msg[1]; I GET AN ERROR ON THIS LINE SAYING "SUBSCRIPT USED WITH NON-ARRAY VARIABLE" Case $ahInput[$i][3] whatever() Case $ahInput[$i][4] msgbox(0, "","") EndSwitch Next WEnd Func whatever() ;;;; EndFunc Edited June 22, 2009 by coder09 Link to comment Share on other sites More sharing options...
BugFix Posted June 22, 2009 Share Posted June 22, 2009 Maybe, that $ahInput[0][0] does'nt declared ? Best Regards BugFix Link to comment Share on other sites More sharing options...
Hypertrophy Posted June 22, 2009 Author Share Posted June 22, 2009 (edited) No, it has nothing to do with whats inside the loop. This is only a piece of my code, I can't post the whole thing. Edited June 22, 2009 by coder09 Link to comment Share on other sites More sharing options...
99ojo Posted June 22, 2009 Share Posted June 22, 2009 No, it has nothing to do with whats inside the loop. This is only a piece of my code, I can't post the whole thing.Hi,for debug reason: 1) Add a #include <Array.au3>at the beginning of your code2) Add a _Arraydisplay ($msg) before your Switch statement in the For Loop. or see helpfile Function IsArray as well for debugging.;-))Stefan Link to comment Share on other sites More sharing options...
KaFu Posted June 22, 2009 Share Posted June 22, 2009 Cant reproduce, has to have something to do with the stuff you didn't post expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Constants.au3> #include <array.au3> $gui = GUICreate("", 400, 400) $button = GUICtrlCreateButton("", 50, 50, 50, 20) GUISetState() Global $ahInput[2][5] $ahInput[0][0] = 1 While 1 $msg = GUIGetMsg(1) Switch $msg[1] Case $button msgbox(0, "", "whatever") EndSwitch ; loop for handling separate events _ArrayDisplay($msg) For $i = 1 To $ahInput[0][0] Switch $msg[1]; I GET AN ERROR ON THIS LINE SAYING "SUBSCRIPT USED WITH NON-ARRAY VARIABLE" Case $ahInput[$i][3] whatever() Case $ahInput[$i][4] msgbox(0, "","") EndSwitch Next WEnd Func whatever() ;;;; EndFunc 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...
Malkey Posted June 22, 2009 Share Posted June 22, 2009 Please help me solve problem in my code. Or maybe another way to handle the events in For loop without using a Switch statement. It's not runnable but basically shows the structure of my main code and how things work. I am getting an error on line 22 SAYING "SUBSCRIPT USED WITH NON-ARRAY VARIABLE". Is there anything wrong with this code? #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Constants.au3> $gui = GUICreate("", 400, 400) $button = GUICtrlCreateButton("", 50, 50, 50, 20) GUISetState() While 1 $msg = GUIGetMsg(1) Switch $msg[1] Case $button msgbox(0, "", "whatever") EndSwitch ; loop for handling separate events For $i = 1 To $ahInput[0][0] Switch $msg[1]; I GET AN ERROR ON THIS LINE SAYING "SUBSCRIPT USED WITH NON-ARRAY VARIABLE" Case $ahInput[$i][3] whatever() Case $ahInput[$i][4] msgbox(0, "","") EndSwitch Next WEnd Func whatever() ;;;; EndFuncIf the error is here "Switch $msg[1]; I GET AN ERROR ON THIS LINE SAYING "SUBSCRIPT USED WITH NON-ARRAY VARIABLE" " The only array in that line is "$msg[1]". $msg[1] is set here " $msg = GUIGetMsg(1)" So if $msg is not an array after this command, the GUIGetMsg(1) is not working. On a search of the help file on "GUIOnEventMode", I found this, "...when the option GUIOnEventMode is set to 1 - when in this mode GUIGetMsg is NOT used at all." This would explain why $msg[1] produces an error. Because the script is running in on event mode, and GUIGetMsg() does not work. Or, KaFu correct. Link to comment Share on other sites More sharing options...
Hypertrophy Posted June 22, 2009 Author Share Posted June 22, 2009 I have no idea how to use _ArrayDisplay nor how it will help my problem. Can't understand helpfile either. Link to comment Share on other sites More sharing options...
Hypertrophy Posted June 22, 2009 Author Share Posted June 22, 2009 Solved everything with a simple IsArray(). 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