Sign in to follow this  
Followers 0
eJan

How to delete Ctrl created (inside) function

3 posts in this topic

I'm trying to change style or delete controls created inside function using variables, but error was "Error: Variable used without being declared" - see: ;If $msg = $delbtn Then DeleteLabel()

#include <GUIConstants.au3>

GUICreate("My GUI", 120, 170)
GUISetState (@SW_SHOW)

$btn = GUICtrlCreateButton("Create label", 25, 120, 70, 20)

While 1
    $msg = GUIGetMsg()
    If $msg = $btn Then _CreateLabel()
;If $msg = $delbtn Then DeleteLabel(); If enabled "Error: Variable used without being declared"
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Wend
    
Func _CreateLabel()
    $label = GUICtrlCReateLabel("Label", 10, 10, 100, 100, $SS_SUNKEN)
    $delbtn = GUICtrlCreateButton("Delete label", 25, 140, 70, 20)
EndFunc

Func DeleteLabel()
    GUICtrlDelete($label)
EndFunc

Share this post


Link to post
Share on other sites



#include <GUIConstants.au3>

Global $delbtn, $label, $btn

GUICreate("My GUI", 120, 170)

GUISetState(@SW_SHOW)

$btn = GUICtrlCreateButton("Create label", 25, 120, 70, 20)

While 1

$msg = GUIGetMsg()

If $msg = $btn Then _CreateLabel()

If $msg = $delbtn Then DeleteLabel(); If enabled "Error: Variable used without being declared"

If $msg = $gui_event_close Then ExitLoop

WEnd

Func _CreateLabel()

$label = GUICtrlCreateLabel("Label", 10, 10, 100, 100, $ss_sunken)

$delbtn = GUICtrlCreateButton("Delete label", 25, 140, 70, 20)

EndFunc ;==>_CreateLabel

Func DeleteLabel()

GUICtrlDelete($label)

GUICtrlDelete($delbtn)

EndFunc ;==>DeleteLabel

Share this post


Link to post
Share on other sites

Thanks psandu.ro, thats exactly what I need!

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