Sign in to follow this  
Followers 0
Xav

GUICtrlCreateLabel Help

7 posts in this topic

If i press "Daw 1" it will be wrote .. But if i press Daw2 after i've pressed daw1 it will not be wrote , how can it replace Daw1 for Daw2??

#include <GUIConstantsEx.au3>
hah()


Func Hah()
            Local $Button_1, $Button_2 , $button_3, $msg
            GUICreate("BomBom , ChaCha")
               Opt("GUICoordMode", 2)
                   $Button_1 = GUICtrlCreateButton("Activating", 10, 8, 125)
                   $Button_2 = GUICtrlCreateButton("Desactivating/Pause", 0, -1)
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                                GUICtrlCreateLabel("Daw 1", 10, 30)
            Case $msg = $Button_2
                $Activated = GUICtrlCreateLabel("Daw 2",10, 30)
                   GUISetState()      
               EndSelect
               wend
    EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You are creating a second Label control which you place under the first, so it's hiden.

What you want is to update the content of the first Label control.

#include <GUIConstantsEx.au3>

Opt("GUICoordMode", 2)

hah()

Func Hah()
    Local $Button_1, $Button_2 , $button_3, $msg, $label
    GUICreate("BomBom , ChaCha")
    $Button_1 = GUICtrlCreateButton("Activating", 10, 8, 125)
    $Button_2 = GUICtrlCreateButton("Desactivating/Pause", 0, -1)
    GUISetState()
    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
    Case $msg = $Button_1
    $label = GUICtrlCreateLabel("Daw 1", 10, 30)
            Case $msg = $Button_2
                GUICtrlSetData($label, "Daw 2")
    EndSelect
    wend
EndFunc

Formatting again trashed when posting, sorry for that.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Create lables before main loop and

GUICtrlSetState($lable_1, $GUI_HIDE)

GUICtrlSetState($lable_2, $GUI_SHOW)

Or create one lable and GUICtrlSetData to change it

Edit: jchd was faster :(

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

Each time your pressing a button your creating a new label in the same place have made some changes see below

#include <GUIConstantsEx.au3>
hah()


Func Hah()
            Local $Button_1, $Button_2 , $button_3, $msg
            GUICreate("BomBom , ChaCha")
               Opt("GUICoordMode", 2)
                   $Button_1 = GUICtrlCreateButton("Activating", 10, 8, 125)
                   $Button_2 = GUICtrlCreateButton("Desactivating/Pause", 0, -1)
                   $hLabel = GUICtrlCreateLabel("Daw 1", 10, 30) ; added this to create the label outside of the loop
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
;~              GUICtrlCreateLabel("Daw 1", 10, 30)
                GUICtrlSetData($hLabel,"Daw 1") ; added this to change label value to 'Daw 1'
            Case $msg = $Button_2
;~                $Activated = GUICtrlCreateLabel("Daw 2",10, 30)
;~                   GUISetState()
                GUICtrlSetData($hLabel,"Daw 2") ; added this to change label value to 'Daw 2'
               EndSelect
               wend
    EndFunc

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Each time your pressing a button your creating a new label in the same place have made some changes see below

#include <GUIConstantsEx.au3>
hah()


Func Hah()
            Local $Button_1, $Button_2 , $button_3, $msg
            GUICreate("BomBom , ChaCha")
               Opt("GUICoordMode", 2)
                   $Button_1 = GUICtrlCreateButton("Activating", 10, 8, 125)
                   $Button_2 = GUICtrlCreateButton("Desactivating/Pause", 0, -1)
                   $hLabel = GUICtrlCreateLabel("Daw 1", 10, 30) ; added this to create the label outside of the loop
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
;~              GUICtrlCreateLabel("Daw 1", 10, 30)
                GUICtrlSetData($hLabel,"Daw 1") ; added this to change label value to 'Daw 1'
            Case $msg = $Button_2
;~                $Activated = GUICtrlCreateLabel("Daw 2",10, 30)
;~                   GUISetState()
                GUICtrlSetData($hLabel,"Daw 2") ; added this to change label value to 'Daw 2'
               EndSelect
               wend
    EndFunc

THanks .. :(

If i have a while in it how can the button 2 stop it ?

Sry i'm new with the Gui's Functions...

#include <GUIConstantsEx.au3>
hah()


Func Hah()
            Local $Button_1, $Button_2 , $button_3, $msg
            GUICreate("BomBom , ChaCha")
               Opt("GUICoordMode", 2)
                   $Button_1 = GUICtrlCreateButton("Activating", 10, 8, 125)
                   $Button_2 = GUICtrlCreateButton("Desactivating/Pause", 0, -1)
                   $hLabel = GUICtrlCreateLabel("Daw 1", 10, 30) ; added this to create the label outside of the loop
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop ; It Doesnt work anymore too.
            Case $msg = $Button_1
                While 1
                                     sleep(1)
                    Wend
;~              GUICtrlCreateLabel("Daw 1", 10, 30)
                GUICtrlSetData($hLabel,"Daw 1") ; added this to change label value to 'Daw 1'
            Case $msg = $Button_2
                GUICtrlSetData($hLabel,"Daw 2") ; added this to change label value to 'Daw 2'
               EndSelect
               wend
    EndFunc
Edited by Xav

Share this post


Link to post
Share on other sites

Don't put so much work inside the GUIGetMsg() check. Just change some flags or something simple, then let the rest of the While/WEnd loop do the work. In this demo, the $f_Run flag is changed by the buttons, and rest of the loop just works off of that:

#include <GUIConstantsEx.au3>

Main()

Func Main()
    Local $idButton_1, $idButton_2, $idLabel, $msg
    Local $f_Run = False, $iTimer, $iData = 0

    GUICreate("Test GUI", 300, 300)
    $idButton_1 = GUICtrlCreateButton("Activating", 100, 20, 100, 30)
    $idButton_2 = GUICtrlCreateButton("Desactivating/Pause", 100, 70, 100, 30)
    $idLabel = GUICtrlCreateLabel("Not started yet.", 20, 120, 260, 20)
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idButton_1
                $f_Run = True
                GUICtrlSetData($idLabel, "Started...")
                $iTimer = TimerInit()
            Case $idButton_2
                $f_Run = False
                GUICtrlSetData($idLabel, "Paused...")
        EndSwitch

        If $f_Run Then
            If TimerDiff($iTimer) >= 1000 Then
                $iData += 1
                GUICtrlSetData($idLabel, "Running:  $iData = " & $iData)
                $iTimer = TimerInit()
            EndIf
        EndIf
    WEnd
EndFunc   ;==>Main

:(


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

PsaltyDS always beats me on the line. Anyway, let me expose something slightly different.

You may possibly use one button only and change its label to reflect the current start/stop state.

#include <GUIConstantsEx.au3>

Opt("GUICoordMode", 2)

hah()

Func Hah()

Local $Button_1, $Button_2 , $button_3, $msg, $label

GUICreate("BomBom , ChaCha")

$Button_1 = GUICtrlCreateButton("Click to start", 10, 8, 125)

;~ $Button_2 = GUICtrlCreateButton("Desactivating/Pause", 0, -1)

$label = GUICtrlCreateLabel("", 10, 30)

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $Button_1

If GUICtrlRead($Button_1) = "Activating" Then

GUICtrlSetData($Button_1, "Desactivating/Pause")

GUICtrlSetData($label, "Daw 2")

Else

GUICtrlSetData($Button_1, "Activating")

GUICtrlSetData($label, "Daw 1")

EndIf

EndSelect

wend

EndFunc

If you have the need to interrupt a loop as you say, you can find it more convenient to use OnEvent functions. They are linked to your control(s) and launch asynchronously. Here's a transposition of the above with OnEvent:

#include <GUIConstantsEx.au3>
#include <Date.au3>

AutoItSetOption("GUIOnEventMode", 1)        ;; <<-- here's the OnEvent trigger
AutoItSetOption("GUICoordMode", 2)

Global $Button_1, $label
Global $daw = 0, $clicks

GUICreate("BomBom , ChaCha")
GUISetOnEvent($GUI_EVENT_CLOSE, "_BomBomClose")

$Button_1 = GUICtrlCreateButton("Click to start", 10, 8, 125)
GUICtrlSetOnEvent(-1, "_Button1")

$label = GUICtrlCreateLabel("", 10, 30)

GUISetState()

hah()

; place applicative code here
Func Hah()
    Local $time = TimerInit()
    ConsoleWrite("Hi " & @UserName & ", how are you?" & @LF)
    While 1
        ConsoleWrite(StringFormat("This sample application has been running for about %.2f seconds\n", TimerDiff($time)))
        ConsoleWrite("Current setting is Daw " & $daw & @LF)
        ConsoleWrite("You have clicked " & $clicks & " times on the button" & @LF)
        ConsoleWrite("It is now " & _Now() & @LF)
        Sleep(Random(500, 5000, 1))
    Wend
EndFunc



; asynchronous actions on control get handled by these OnEvent functions


Func _Button1()
    $clicks += 1
    If GUICtrlRead($Button_1) = "Activating" Then
        GUICtrlSetData($Button_1, "Desactivating/Pause")
        GUICtrlSetData($label, "Daw 2")
        $daw = 2
    Else
        GUICtrlSetData($Button_1, "Activating")
        GUICtrlSetData($label, "Daw 1")
        $daw = 1
    EndIf
EndFunc


Func _BomBomClose()
    MsgBox(0, "BomBom", "Application will now close")
    Exit
EndFunc

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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