Jump to content

Updating label text


Recommended Posts

Okay, so this is my problem: When I have my code like this, the text updates as I want it to do, but I am unable to use the close/minimize control buttons.

$var1 = 0

GUICreate("", 200, 200)
$Label1 = GUICtrlCreateLabel($var1, 100, 100, 50, 50)
GUICtrlSetFont(-1, 38, 400, 0, "Arial Rounded MT Bold")
GUICtrlSetColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)

Sleep(1000)
$var1 += 1
GUICtrlSetData($Label1, $var1)
Sleep(1000)
$var1 += 1
GUICtrlSetData($Label1, $var1)
Sleep(1000)
$var1 += 1
GUICtrlSetData($Label1, $var1)
Sleep(1000)
Exit

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3
            Exit

    EndSwitch
WEnd

If I have the other way around, like this, I can close and minimize, but it doesn't update the label text.

$var1 = 0

GUICreate("", 200, 200)
$Label1 = GUICtrlCreateLabel($var1, 100, 100, 50, 50)
GUICtrlSetFont(-1, 38, 400, 0, "Arial Rounded MT Bold")
GUICtrlSetColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3
            Exit

    EndSwitch
WEnd

Sleep(1000)
$var1 += 1
GUICtrlSetData($Label1, $var1)
Sleep(1000)
$var1 += 1
GUICtrlSetData($Label1, $var1)
Sleep(1000)
$var1 += 1
GUICtrlSetData($Label1, $var1)
Sleep(1000)
Exit

Help would be appreciated.

Link to comment
Share on other sites

You can use AdlibRegister to do this

 

GUICreate("", 200, 200)
Global $Label1 = GUICtrlCreateLabel("1", 100, 100, 50, 50)
GUICtrlSetFont(-1, 38, 400, 0, "Arial Rounded MT Bold")
GUICtrlSetColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)

AdlibRegister("_Count", 1000)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3
            Exit
    EndSwitch
WEnd


Func _Count()
    Local Static $var1 = 1
    $var1 += 1
    If $var1 = 4 Then Exit
    GUICtrlSetData($Label1, $var1)
EndFunc

 

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

  • Moderators

Marzupilami,

Just look for the events during the pauses:

#include <GUIConstantsEx.au3>

$var1 = 0

GUICreate("", 200, 200)
$Label1 = GUICtrlCreateLabel($var1, 100, 100, 50, 50)
GUICtrlSetFont(-1, 38, 400, 0, "Arial Rounded MT Bold")
GUICtrlSetColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)

_Sleep(1000)
$var1 += 1
GUICtrlSetData($Label1, $var1)
_Sleep(1000)
$var1 += 1
GUICtrlSetData($Label1, $var1)
_Sleep(1000)
$var1 += 1
GUICtrlSetData($Label1, $var1)
_Sleep(1000)
Exit

Func _Sleep($iDelay)
    $nBegin = TimerInit()
    While TimerDiff($nBegin) < $iDelay
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@funkey, @Melba23: Thank you for your quick responses! I'm sorry I was a bit unclear. In fact I don't want a counter like the one I showed. What I want is that as thevalue of $var1 changes during the script (my real script is much longer) I want the label text to update with it. Could you help me with that?

Link to comment
Share on other sites

  • Moderators

Marzupilami,

It always helps to give as much detail as possible when asking a question - then responders do not waste their time producing code which does not do what is actually required.

Two possible solutions to your problem spring to mind:

  1. When you reach the part of your script where you change the value of the variable in question, update the label at that point.
  2. Use Adlib to read the current value and update the label, much as funkey has already suggested.

If you want more focused help, I suggest posting your script so we can see just what might best fit the bill.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Use the OnEvent-Mode.This makes it easier to handle larger scripts and avoids such problems.

Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

  • Moderators

funkey,

I must disagree with that last remark - I have used both OnEvent and MessageLoop modes in large scripts and I would argue that the latter is easier to code and just as efficient.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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