Jump to content

Recommended Posts

Posted

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
Posted

#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

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
  • Recently Browsing   0 members

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