Jump to content

Please help! [FIXED]


Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...