Sign in to follow this  
Followers 0
Marlo

Function problem

2 posts in this topic

#1 ·  Posted (edited)

OK so i am having a little trouble with my script.

You see i am writing a script with a GUI and whenever i write GUI's i have them use the OnEvent method

Example:

Opt("GUIOnEventMode", 1)

$winMain = GUICreate("app", 640, 260, 193, 150)
$Label1 = GUICtrlCreateLabel("Directory", 24, 66, 83, 17)
$btnAdd = GUICtrlCreateButton("Add File", 160, 216, 75, 25, 0)
GUISetState(@SW_SHOW)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUICtrlSetOnEvent($btnAdd, "_ToggleButtons")

While 1

Wend

Func _Exit()
Exit
EndFunc

Func _ToggleButtons($switch = False)
If $Switch = False Then
Do stuff
EndIF
EndFuncoÝ÷ ØÚ0¶¢%x­¶ì~éܶ*'Âä±ø§{^Æ¥çméè®f¥Á¬ºÚ"µÍÕÙÙÛP]ÛÊYJ

But when i call GUICtrlOnEvent($btnAdd, "_ToggleButtons") I get an error "Variable used without being declared.:"

Now i have made the parameter in the function optional but still the error persists. Can anyone shed some light onto this? much apreciated.

Edited by Marlo

Click here for the best AutoIt help possible.Currently Working on: Autoit RAT

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can´t call a function with parameters in GUICtrlSetOnEvent()

You have to use a global variable

Example:

Opt("GUIOnEventMode", 1)

$switch = 0
$winMain = GUICreate("app", 640, 260, 193, 150)
$Label1 = GUICtrlCreateLabel("Directory", 24, 66, 83, 17)
$btnAdd = GUICtrlCreateButton("Add File", 160, 216, 75, 25, 0)
GUISetState(@SW_SHOW)
GUISetOnEvent(-3, "_Exit")
GUICtrlSetOnEvent($btnAdd, "ToggleButtons")

While 1
    Sleep(1000)
Wend

Func _Exit()
    Exit
EndFunc

Func ToggleButtons()
    If $switch == 0 Then
        $switch = 1
    Else
        $switch = 0
    EndIf
    MsgBox(0,"",$switch)
EndFunc
Edited by bluelamp

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  
Followers 0