Jump to content
Sign in to follow this  
Hypertrophy

Please help! [FIXED]

Recommended Posts

Hypertrophy

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 by coder09

Share this post


Link to post
Share on other sites
BugFix

Maybe, that $ahInput[0][0] does'nt declared ?


Best Regards BugFix  

Share this post


Link to post
Share on other sites
Hypertrophy

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 by coder09

Share this post


Link to post
Share on other sites
99ojo

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 code

2) Add a _Arraydisplay ($msg) before your Switch statement in the For Loop.

or see helpfile Function IsArray as well for debugging.

;-))

Stefan

Share this post


Link to post
Share on other sites
KaFu

Cant reproduce, has to have something to do with the stuff you didn't post

#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

Share this post


Link to post
Share on other sites
Malkey

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
If 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.

Share this post


Link to post
Share on other sites
Hypertrophy

I have no idea how to use _ArrayDisplay nor how it will help my problem. Can't understand helpfile either.

Share this post


Link to post
Share on other sites
Hypertrophy

Solved everything with a simple IsArray(). :D

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.