Sign in to follow this  
Followers 0
BALA

help with GUICtrlSetData

9 posts in this topic

#1 ·  Posted (edited)

Zenda suggested I edit my code to have a GUICtrlSetData command to save memory. Right now I have my program display the X and Y positions of a coordinate. It continuously creates a new label every time it goes though the loop, using up memory. What I need help with is how I could update the X and Y positions using the GUICtrlSetData since the help file was a little unclear to me.

Original script:

#include <Misc.au3>
#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
$mainwindow = GUICreate("BA-TYPER", 300, 160)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState()

$position1 = GUICtrlCreateButton("Position", 70, 20, 120)
GUICtrlSetOnEvent($position1, "Position")

$on = GUICtrlCreateRadio ("On", 40, 60, 40, 20)
$off = GUICtrlCreateRadio ("Off", 40, 80, 40, 20)
GUICtrlSetState ($off, $GUI_CHECKED)
$input = GUICtrlCreateInput("", 80, 70, 180, 20)

$checkbox = GUICtrlCreateCheckbox ("Input an 'Enter' after text", 41, 100, 140, 20)

$time = GUICtrlCreateInput("5", 210, 127, 40, 20)
GUICtrlCreateLabel ("Time between Posts (in seconds)", 40, 130)

Dim $Position, $i = 0, $Record[1][2]
Global $check = 0

Func CLOSEClicked()
  Exit
EndFunc

Func Position()
  While 1
        If _IsPressed("01") Then
            $Position = MouseGetPos()
            ReDim $Record[$i + 1][2]
            $Record[$i][0] = $Position[0]
            $Record[$i][1] = $position[1]
            GUICtrlCreateLabel ("x = "&$Record[$i][0] & @LF & "y = "& $Record[$i][1] & @LF,  200, 20)
            $i += 1
            ExitLoop
        EndIf
        sleep(10)
    WEnd
EndFunc

While 1
    If GUICtrlRead($on) = $GUI_CHECKED Then
        $check = 1
    EndIf
    If GUICtrlRead($off) = $GUI_CHECKED Then
        $check = 0
    EndIf
    If $check = 1 Then
        MouseClick("left", $Position[0], $position[1], 1)
        Send (""&GuiCtrlRead($input))
        If GUICtrlRead($checkbox) = $GUI_CHECKED Then
            Send("{ENTER}")
        EndIf
        sleep(1000 * GuiCtrlRead($time))
    EndIf
    sleep(10)
WEndoÝ÷ ØÊøu«­¢+Ø¥¹±Õ±Ðí5¥Í¹ÔÌÐì(¥¹±Õ±ÐíU%
½¹ÍѹÑ̹ÔÌÐì()=ÁÐ ÅÕ½ÐíU%=¹Ù¹Ñ5½ÅÕ½Ðì°Ä¤(ÀÌØíµ¥¹Ý¥¹½ÜôU%
ÉÑ ÅÕ½Ðí µQeAHÅÕ½Ðì°ÌÀÀ°ÄØÀ¤)U%MÑ=¹Ù¹Ð ÀÌØíU%}Y9Q}
1=M°ÅÕ½Ðí
1=M
±¥­ÅÕ½Ðì¤)U%MÑMÑÑ ¤((ÀÌØíÁ½Í¥Ñ¥½¸ÄôU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½ÐíA½Í¥Ñ¥½¸ÅÕ½Ðì°ÜÀ°ÈÀ°ÄÈÀ¤)U%
ÑɱMÑ=¹Ù¹Ð ÀÌØíÁ½Í¥Ñ¥½¸Ä°ÅÕ½ÐíA½Í¥Ñ¥½¸ÅÕ½Ðì¤((í¡ÉÌäíÌÑ¡±°)U%
Ñɱ
ÉÑ1° ÅÕ½ÐíàôÅÕ½ÐìµÀìÀÌØíI½ÉlÀÌØí¥ulÁtµÀì1µÀìÅÕ½ÐíäôÅÕ½ÐìµÀìÀÌØíI½ÉlÀÌØí¥ulÅtµÀì1°ÈÀÀ°ÈÀ¤((ÀÌØí½¸ôU%
Ñɱ
ÉÑI¥¼ ÅÕ½Ðí=¸ÅÕ½Ðì°ÐÀ°ØÀ°ÐÀ°ÈÀ¤(ÀÌØí½ôU%
Ñɱ
ÉÑI¥¼ ÅÕ½Ðí=ÅÕ½Ðì°ÐÀ°àÀ°ÐÀ°ÈÀ¤)U%
ÑɱMÑMÑÑ ÀÌØí½°ÀÌØíU%}
!
-¤(ÀÌØí¥¹ÁÕÐôU%
Ñɱ
ÉÑ%¹ÁÕÐ ÅÕ½ÐìÅÕ½Ðì°àÀ°ÜÀ°ÄàÀ°ÈÀ¤((ÀÌØí¡­½àôU%
Ñɱ
ÉÑ
¡­½à ÅÕ½Ðí%¹ÁÕиÌäí¹ÑÈÌäìÑÈÑáÐÅÕ½Ðì°ÐÄ°ÄÀÀ°ÄÐÀ°ÈÀ¤((ÀÌØíÑ¥µôU%
Ñɱ
ÉÑ%¹ÁÕÐ ÅÕ½ÐìÔÅÕ½Ðì°ÈÄÀ°ÄÈÜ°ÐÀ°ÈÀ¤)U%
Ñɱ
ÉÑ1° ÅÕ½ÐíQ¥µÑݸA½ÍÑÌ¡¥¸Í½¹Ì¤ÅÕ½Ðì°ÐÀ°ÄÌÀ¤()¥´ÀÌØíA½Í¥Ñ¥½¸°ÀÌØí¤ôÀ°ÀÌØíI½ÉlÅulÉt)±½°ÀÌØí¡¬ôÀ()Õ¹
1=M
±¥­ ¤(á¥Ð)¹Õ¹()Õ¹A½Í¥Ñ¥½¸ ¤(]¡¥±Ä($%%}%ÍAÉÍÍ ÅÕ½ÐìÀÄÅÕ½Ðì¤Q¡¸($$$ÀÌØíA½Í¥Ñ¥½¸ô5½ÕÍÑA½Ì ¤($$%I¥´ÀÌØíI½ÉlÀÌØí¤¬ÅulÉt($$$ÀÌØíI½ÉlÀÌØí¥ulÁtôÀÌØíA½Í¥Ñ¥½¹lÁt($$$ÀÌØíI½ÉlÀÌØí¥ulÅtôÀÌØíÁ½Í¥Ñ¥½¹lÅt($$%U%
ÑɱMÑÑ ¤ì!±À¡É($$$ÀÌØí¤¬ôÄ($$%á¥Ñ1½½À($%¹%($%ͱÀ ÄÀ¤(%]¹)¹Õ¹()]¡¥±Ä(%%U%
ÑɱI ÀÌØí½¸¤ôÀÌØíU%}
!
-Q¡¸($$ÀÌØí¡¬ôÄ(%¹%(%U%
ÑɱI ÀÌØí½¤ôÀÌØíU%}
!
-Q¡¸($$ÀÌØí¡¬ôÀ(%¹%(%%ÀÌØí¡¬ôÄQ¡¸($%5½ÕÍ
±¥¬ ÅÕ½Ðí±ÐÅÕ½Ðì°ÀÌØíA½Í¥Ñ¥½¹lÁt°ÀÌØíÁ½Í¥Ñ¥½¹lÅt°Ä¤($%M¹ ÅÕ½ÐìÅÕ½ÐìµÀíÕ¥
ÑɱI ÀÌØí¥¹ÁÕФ¤($%%U%
ÑɱI ÀÌØí¡­½à¤ôÀÌØíU%}
!
-Q¡¸($$%M¹ ÅÕ½Ðíí9QIôÅÕ½Ðì¤($%¹%($%ͱÀ ÄÀÀÀ¨Õ¥
ÑɱI ÀÌØíÑ¥µ¤¤(%¹%(%ͱÀ ÄÀ¤)]¹
Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <Misc.au3>

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
$mainwindow = GUICreate("BA-TYPER", 300, 160)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState()

$position1 = GUICtrlCreateButton("Position", 70, 20, 120)
GUICtrlSetOnEvent($position1, "Position")

;Give your label a variable...
$label = GUICtrlCreateLabel ("x = "&$Record[$i][0] & @LF & "y = "& $Record[$i][1] & @LF,  200, 20)

$on = GUICtrlCreateRadio ("On", 40, 60, 40, 20)
$off = GUICtrlCreateRadio ("Off", 40, 80, 40, 20)
GUICtrlSetState ($off, $GUI_CHECKED)
$input = GUICtrlCreateInput("", 80, 70, 180, 20)

$checkbox = GUICtrlCreateCheckbox ("Input an 'Enter' after text", 41, 100, 140, 20)

$time = GUICtrlCreateInput("5", 210, 127, 40, 20)
GUICtrlCreateLabel ("Time between Posts (in seconds)", 40, 130)

Dim $Position, $i = 0, $Record[1][2]
Global $check = 0

Func CLOSEClicked()
  Exit
EndFunc

Func Position()
  While 1
        If _IsPressed("01") Then
            $Position = MouseGetPos()
            ReDim $Record[$i + 1][2]
            $Record[$i][0] = $Position[0]
            $Record[$i][1] = $position[1]
            GUICtrlSetData($label,"x = "&$Record[$i][0] & @LF & "y = "& $Record[$i][1]) ; <--- Here
            $i += 1
            ExitLoop
        EndIf
        sleep(10)
    WEnd
EndFunc

While 1
    If GUICtrlRead($on) = $GUI_CHECKED Then
        $check = 1
    EndIf
    If GUICtrlRead($off) = $GUI_CHECKED Then
        $check = 0
    EndIf
    If $check = 1 Then
        MouseClick("left", $Position[0], $position[1], 1)
        Send (""&GuiCtrlRead($input))
        If GUICtrlRead($checkbox) = $GUI_CHECKED Then
            Send("{ENTER}")
        EndIf
        sleep(1000 * GuiCtrlRead($time))
    EndIf
    sleep(10)
WEnd
Edited by eynstyne

F@m!ly Guy Fr33k! - Avatar speaks for itself__________________________________________________________________________________________ite quotes... - Is your refrigerator running? If it is, It probably runs like you...very homosexually - Christians don't believe in gravity - Geeze Brian where do you think you are, Payless?- Show me potato Salad!__________________________________________________________________________________________Programs available - Shutdown timer[indent][/indent]

Share this post


Link to post
Share on other sites

GUICtrlCreateLabel returns "the identifier (controlID) of the new control".

The first parameter of GUICtrlSetData should be "the control identifier (controlID) as returned by a GUICtrlCreate... function."

$id = GUICtrlCreateLabel("initial text", 10, 10, 280, 20)
GUICtrlSetData($id, "updated text")

Simple.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Would I just create the label, without any thing in it, and move the text I currently have in the label to the GuiCtrlSetData?

I.E. :

#include <Misc.au3>
#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
$mainwindow = GUICreate("BA-TYPER", 300, 160)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState()

$position1 = GUICtrlCreateButton("Position", 70, 20, 120)
GUICtrlSetOnEvent($position1, "Position")

;here's the label
$label = GUICtrlCreateLabel ("",  200, 20)

$on = GUICtrlCreateRadio ("On", 40, 60, 40, 20)
$off = GUICtrlCreateRadio ("Off", 40, 80, 40, 20)
GUICtrlSetState ($off, $GUI_CHECKED)
$input = GUICtrlCreateInput("", 80, 70, 180, 20)

$checkbox = GUICtrlCreateCheckbox ("Input an 'Enter' after text", 41, 100, 140, 20)

$time = GUICtrlCreateInput("5", 210, 127, 40, 20)
GUICtrlCreateLabel ("Time between Posts (in seconds)", 40, 130)

Dim $Position, $i = 0, $Record[1][2]
Global $check = 0

Func CLOSEClicked()
  Exit
EndFunc

Func Position()
  While 1
        If _IsPressed("01") Then
            $Position = MouseGetPos()
            ReDim $Record[$i + 1][2]
            $Record[$i][0] = $Position[0]
            $Record[$i][1] = $position[1]
            GUICtrlSetData($label, "x = "&$Record[$i][0] & @LF & "y = "& $Record[$i][1] & @LF) ; <--- Moved text here
            $i += 1
            ExitLoop
        EndIf
        sleep(10)
    WEnd
EndFunc

While 1
    If GUICtrlRead($on) = $GUI_CHECKED Then
        $check = 1
    EndIf
    If GUICtrlRead($off) = $GUI_CHECKED Then
        $check = 0
    EndIf
    If $check = 1 Then
        MouseClick("left", $Position[0], $position[1], 1)
        Send (""&GuiCtrlRead($input))
        If GUICtrlRead($checkbox) = $GUI_CHECKED Then
            Send("{ENTER}")
        EndIf
        sleep(1000 * GuiCtrlRead($time))
    EndIf
    sleep(10)
WEnd
Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

It's your choice to leave it blank or not... Or you can take make your label llook like this

x = 0 y = 0

then fill it in after


F@m!ly Guy Fr33k! - Avatar speaks for itself__________________________________________________________________________________________ite quotes... - Is your refrigerator running? If it is, It probably runs like you...very homosexually - Christians don't believe in gravity - Geeze Brian where do you think you are, Payless?- Show me potato Salad!__________________________________________________________________________________________Programs available - Shutdown timer[indent][/indent]

Share this post


Link to post
Share on other sites

I now have this:

#include <Misc.au3>
#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
$mainwindow = GUICreate("BA-TYPER", 300, 160)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState()

$position1 = GUICtrlCreateButton("Position", 70, 20, 120)
GUICtrlSetOnEvent($position1, "Position")
$label = GUICtrlCreateLabel ("x = " & @LF & "y = "& @LF,  200, 20)

$on = GUICtrlCreateRadio ("On", 40, 60, 40, 20)
$off = GUICtrlCreateRadio ("Off", 40, 80, 40, 20)
GUICtrlSetState ($off, $GUI_CHECKED)
$input = GUICtrlCreateInput("", 80, 70, 180, 20)

$checkbox = GUICtrlCreateCheckbox ("Input an 'Enter' after text", 41, 100, 140, 20)

$time = GUICtrlCreateInput("5", 210, 127, 40, 20)
GUICtrlCreateLabel ("Time between Posts (in seconds)", 40, 130)

Dim $Position, $i = 0, $Record[1][2]
Global $check = 0

Func CLOSEClicked()
  Exit
EndFunc

Func Position()
  While 1
        If _IsPressed("01") Then
            $Position = MouseGetPos()
            ReDim $Record[$i + 1][2]
            $Record[$i][0] = $Position[0]
            $Record[$i][1] = $position[1]
            GUICtrlSetData($label,"x = "& $Record[$i][0] & @LF & "y = "& $Record[$i][1])
            $i += 1
            ExitLoop
        EndIf
        sleep(10)
    WEnd
EndFunc

While 1
    If GUICtrlRead($on) = $GUI_CHECKED Then
        $check = 1
    EndIf
    If GUICtrlRead($off) = $GUI_CHECKED Then
        $check = 0
    EndIf
    If $check = 1 Then
        MouseClick("left", $Position[0], $position[1], 1)
        Send (""&GuiCtrlRead($input))
        If GUICtrlRead($checkbox) = $GUI_CHECKED Then
            Send("{ENTER}")
        EndIf
        sleep(1000 * GuiCtrlRead($time))
    EndIf
    sleep(10)
WEnd

But now it has the numbers under the X or Y

How do I make the numbers be like they were in the original script?


[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Remove the @LF and @CRLF Line feeds

You may also want to set a width and height for your label or else it will wrap around

$label = GUICtrlCreateLabel ("x = " & " " & "y = "& " ", 200, 20,200,20) ; In place of @LF , " "

Edited by eynstyne

F@m!ly Guy Fr33k! - Avatar speaks for itself__________________________________________________________________________________________ite quotes... - Is your refrigerator running? If it is, It probably runs like you...very homosexually - Christians don't believe in gravity - Geeze Brian where do you think you are, Payless?- Show me potato Salad!__________________________________________________________________________________________Programs available - Shutdown timer[indent][/indent]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

oh! Forgot to delete that when I copied and pasted :P

EDIT: I don't think that was the problem

Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

Like Jesus said to the lonely sheep...specify a width and height on your labels and your problems will be solved.

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