Jump to content

How can i change color of text in a loop


russell
 Share

Recommended Posts

I have a timer below that starts at 60 and begins when you hit keys 1-7. It counts to 0 then the value just says tray. My question is how do i get it to show the text in red when there is no numbers i.e. when it says tray? You can see at the bottom i played around with it but no luck, its either green or red.

#include <GUIConstants.au3>
 
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Tray Warming Timer", 1000, 800, 0, 0)
$Label1 = GUICtrlCreateLabel("60:00", 1, 8, 950, 152)
GUICtrlSetFont(-1, 80, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$Label2 = GUICtrlCreateLabel("60:00", 1, 118, 950, 152)
GUICtrlSetFont(-2, 80, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-2, 0x00FF00)
$Label3 = GUICtrlCreateLabel("60:00", 1, 228, 950, 152)
GUICtrlSetFont(-3, 80, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-3, 0x00FF00)
$Label4 = GUICtrlCreateLabel("60:00", 1, 338, 950, 152)
GUICtrlSetFont(-4, 80, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-41, 0x00FF00)
$Label5 = GUICtrlCreateLabel("60:00", 1, 448, 950, 152)
GUICtrlSetFont(-5, 80, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-5, 0x00FF00)
$Label6 = GUICtrlCreateLabel("60:00", 1, 558, 950, 152)
GUICtrlSetFont(-6, 80, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-6, 0x00FF00)
$Label7 = GUICtrlCreateLabel("60:00", 1, 668, 950, 152)
GUICtrlSetFont(-7, 80, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-7, 0x00FF00)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$startmins = 60 ;in mins
$renew = 59
$time= 0
$time2 = 0
$time3 = 0
$time4 = 0
$time5 = 0
$time6 = 0
$time7 = 0
HotKeySet("{1}", "rest1")
Func rest1()
       $time=TimerInit()
    $loop1 = 1 ;null marker
  
EndFunc
HotKeySet("{2}", "rest2")
Func rest2()
       $time2=TimerInit()
    $loop2 = 1 ;null marker
EndFunc
HotKeySet("{3}", "rest3")
Func rest3()
       $time3=TimerInit()
    $loop3 = 1 ;null marker
 
EndFunc
HotKeySet("{4}", "rest4")
Func rest4()
       $time4=TimerInit()
    $loop4 = 1 ;null marker
EndFunc
  
HotKeySet("{5}", "rest5")
Func rest5()
       $time5=TimerInit()
EndFunc
HotKeySet("{6}", "rest6")
Func rest6()
       $time6=TimerInit()
    $loop6 = 1 ;null marker
EndFunc
HotKeySet("{7}", "rest7")
Func rest7()
       $time7=TimerInit()
    $loop7 = 1 ;null marker
EndFunc
 
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
 
    EndSwitch
 
;~  --------------------------------
   $new = TimerDiff ($time)
$new2 = TimerDiff ($time2)
$new3 = TimerDiff ($time3)
$new4 = TimerDiff ($time4)
$new5 = TimerDiff ($time5)
$new6 = TimerDiff ($time6)
$new7 = TimerDiff ($time7)
;~   ------------------------------
$new = ($startmins*60*1000)-$new
$new2 = ($startmins*60*1000)-$new2
$new3 = ($startmins*60*1000)-$new3
$new4 = ($startmins*60*1000)-$new4
$new5 = ($startmins*60*1000)-$new5
$new6 = ($startmins*60*1000)-$new6
$new7 = ($startmins*60*1000)-$new7
;~ ----------------------------------
  
$seconds = Round ($new/1000)
$seconds2 = Round ($new2/1000)
    $seconds3 = Round ($new3/1000)
$seconds4 = Round ($new4/1000)
$seconds5 = Round ($new5/1000)
$seconds6 = Round ($new6/1000)
$seconds7 = Round ($new7/1000)
;~  -------------------------------------
$newMin = Floor ($seconds/60)
if $newMin < 0 then $newmin = "Tray "
$newMin2 = Floor ($seconds2/60)
if $newMin2 < 0 then $newmin2 = "Tray "
$newMin3 = Floor ($seconds3/60)
if $newMin3 < 0 then $newmin3 = "Tray "
$newMin4 = Floor ($seconds4/60)
if $newMin4 < 0 then $newmin4 = "Tray "
$newMin5 = Floor ($seconds5/60)
if $newMin5 < 0 then $newmin5 = "Tray "
$newMin6 = Floor ($seconds6/60)
if $newMin6 < 0 then $newmin6 = "Tray "
$newMin7 = Floor ($seconds7/60)
if $newMin7 < 0 then $newmin7 = "Tray "
 
;~  ------------------------------------
    $newSec = Mod ($seconds, 60)
if $newSec < 0 then $newSec = "1"
$newSec2 = Mod ($seconds2, 60)
if $newSec2 < 0 then $newSec2 = "2"
$newSec3 = Mod ($seconds3, 60)
if $newSec3 < 0 then $newSec3 = "3"
$newSec4 = Mod ($seconds4, 60)
if $newSec4 < 0 then $newSec4 = "4"
$newSec5 = Mod ($seconds5, 60)
if $newSec5 < 0 then $newSec5 = "5"
$newSec6 = Mod ($seconds6, 60)
if $newSec6 < 0 then $newSec6 = "6"
$newSec7 = Mod ($seconds7, 60)
if $newSec7 < 0 then $newSec7 = "7"
;~  ------------------------------------
 
    If $newSec < 10 Then $newSec = "0"&$newSec
    GUICtrlSetData ($Label1, $newMin&":"&$newSec)
If $newSec2 < 10 Then $newSec2 = "0"&$newSec2
    GUICtrlSetData ($Label2, $newMin2&":"&$newSec2)
If $newSec3 < 10 Then $newSec3 = "0"&$newSec3
    GUICtrlSetData ($Label3, $newMin3&":"&$newSec3)
If $newSec4 < 10 Then $newSec4 = "0"&$newSec4
    GUICtrlSetData ($Label4, $newMin4&":"&$newSec4)
If $newSec5 < 10 Then $newSec5 = "0"&$newSec5
    GUICtrlSetData ($Label5, $newMin5&":"&$newSec5)
If $newSec6 < 10 Then $newSec6 = "0"&$newSec6
    GUICtrlSetData ($Label6, $newMin6&":"&$newSec6)
If $newSec7 < 10 Then $newSec7 = "0"&$newSec7
    GUICtrlSetData ($Label7, $newMin7&":"&$newSec7)
;-------------------------------------------------------------
If $newSec+$newMin < 0 Then $newSec =0
     GUICtrlSetData ($Label1, $newMin&":"&$newSec)
If $newSec2+$newMin2 < 0 Then $newSec2 =0
  GUICtrlSetData ($Label2, $newMin2&":"&$newSec2)
If $newSec3+$newMin3 < 0 Then $newSec3 =0
  GUICtrlSetData ($Label3, $newMin3&":"&$newSec3)
If $newSec4+$newMin4 < 0 Then $newSec4 =0
  GUICtrlSetData ($Label4, $newMin4&":"&$newSec4)
If $newSec5+$newMin5 < 0 Then $newSec5 =0
  GUICtrlSetData ($Label5, $newMin5&":"&$newSec5)
If $newSec6+$newMin6 < 0 Then $newSec6 =0
  GUICtrlSetData ($Label6, $newMin6&":"&$newSec6)
If $newSec7+$newMin7 < 0 Then $newSec7 =0
  GUICtrlSetData ($Label7, $newMin7&":"&$newSec7)
 
If $newMin = "tray" Then GUICtrlSetColor(-1, 0x0FF000)
If $newMin7 = "tray" Then $Label7 = GUICtrlSetFont(-1, 80, 400, 0, "MS Sans Serif")
  GUICtrlSetColor(-1, 0xFF0000)
 
  Sleep (1000)
 
WEnd

muppet hands are so soft :)

Link to comment
Share on other sites

  • Moderators

russell,

You really need to learn about arrays and loops! ;)

Take a look at this and see if you can follow: ;)

#include <GUIConstants.au3>

; Set the HotKeys
HotKeySet("1", "rest1")
HotKeySet("2", "rest2")
HotKeySet("3", "rest3")
HotKeySet("4", "rest4")
HotKeySet("5", "rest5")
HotKeySet("6", "rest6")
HotKeySet("7", "rest7")

; Create some arrays to hold the variables
Global $aLabel[7], $aTime[7], $aLoop[7]

; Set the timer variables
$iStart_Mins = 60 ; in mins
$iRenew = 59
$iCheck_Time = TimerInit() ; This is used to change the time every second

$hGUI = GUICreate("Tray Warming Timer", 1000, 800, 0, 0)

; Loop
For $i = 0 To 6

    ; Create the labels, storing their controlIDs in the array
    $aLabel[$i] = GUICtrlCreateLabel($iStart_Mins & ":00", 1, 8 + (110 * $i), 950, 152)
    GUICtrlSetFont(-1, 80, 400, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x00FF00)
    ; And set the time delay in another array
    $aTime[$i] = $iStart_Mins * 60

Next

GUISetState()

; Set the top timer to 10 secs for testing <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$aTime[0] = 10

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Every second, run this section
    If TimerDiff($iCheck_Time) > 1000 Then
        ; Reset the timer to run this section
        $iCheck_Time = TimerInit()
        ; Loop through the arrays
        For $i = 0 To 6
            ; Remove a sec from the timer
            $aTime[$i] -= 1
            ; If the timer is below 0
            If $aTime[$i] < 0 Then
                ; Set the label to "Tray" in RED
                GUICtrlSetData($aLabel[$i], "Tray")
                GUICtrlSetColor($aLabel[$i], 0xFF0000)
            Else
                ; If not then set the label to the time remaining
                ; Note the use of StringFormat to get a leading 0 if required
                $iNew_Min = StringFormat("%02i", Floor($aTime[$i] / 60))
                $iNew_Sec = StringFormat("%02i", Mod($aTime[$i], 60))
                GUICtrlSetData($aLabel[$i], $iNew_Min & ":" & $iNew_Sec)
            EndIf
        Next
    EndIf

WEnd

Func rest1()
    ; Reset the timer to the full value
    $aTime[0] = $iStart_Mins * 60
    $aLoop[0] = 1 ;null marker
EndFunc   ;==>rest1

Func rest2()
    $aTime[1] = $iStart_Mins * 60
    $aLoop[1] = 1 ;null marker
EndFunc   ;==>rest2
Func rest3()
    $aTime[2] = $iStart_Mins * 60
    $aLoop[2] = 1 ;null marker
EndFunc   ;==>rest3
Func rest4()
    $aTime[3] = $iStart_Mins * 60
    $aLoop[3] = 1 ;null marker
EndFunc   ;==>rest4
Func rest5()
    $aTime[4] = $iStart_Mins * 60
    $aLoop[4] = 1 ;null marker
EndFunc   ;==>rest5
Func rest6()
    $aTime[5] = $iStart_Mins * 60
    $aLoop[5] = 1 ;null marker
EndFunc   ;==>rest6
Func rest7()
    $aTime[6] = $iStart_Mins * 60
    $aLoop[6] = 1 ;null marker
EndFunc   ;==>rest7

The <<<<<<<<<<< line is just for testing so you do not have to wait an hour for the colour to change! :)

If you have any questions on anything in the script, please ask. :graduated:

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

honestly i never got into arrays and because of this had a lack of knowledge so i guess i staid away from them entirely. While most of the script makes sense i am unable to understand it as a whole. This my fault not yours in anyway. I think i need to study arrays and just practice for a bit. The amount of questions i already have are not fair to ask because I'm sure i could find these answers in the help. So long story short, Thank You and i will educate myself as much as possible before i ask any questions.

Edited by russell

muppet hands are so soft :)

Link to comment
Share on other sites

hmm i do notice that upon reset of the timer after it has already expired, that the numbers remain red. In my mind i automatically think i need to define somewhere if its a numerical value to be green but i could find nothing to define numbers in values in the help

Edited by russell

muppet hands are so soft :)

Link to comment
Share on other sites

ahh found it

; If not then set the label to the time remaining
                ; Note the use of StringFormat to get a leading 0 if required
                $iNew_Min = StringFormat("%02i", Floor($aTime[$i] / 60))
                $iNew_Sec = StringFormat("%02i", Mod($aTime[$i], 60))
                GUICtrlSetData($aLabel[$i], $iNew_Min & ":" & $iNew_Sec)
    GUICtrlSetColor($aLabel[$i], 0x0FF000)

However i am still uncertain how to start the timers at 0 aka RED

Edited by russell

muppet hands are so soft :)

Link to comment
Share on other sites

Ok this i know im in over my head. If the string is in a numerical value, how to i name it too. I.E. wanting to place the Tray name and the end of the sec...[0]59:01 Pot Pies,[1]48:34 Chicken etc

i keep looking at the below section, trying to mimic it. I assume i make an array to define as a group to be placed somewhere like below but then define each one?

For $i = 0 To 6
    ; Create the labels, storing their controlIDs in the array
    $aLabel[$i] = GUICtrlCreateLabel($iStart_Mins & ":00", 1, 8 + (110 * $i), 950, 152)
    GUICtrlSetFont(-1, 80, 400, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x00FF00)
    ; And set the time delay in another array
    $aTime[$i] = $iStart_Mins * 60
Next
GUISetState()

muppet hands are so soft :)

Link to comment
Share on other sites

  • Moderators

russell,

Have you noticed the "Edit" button? :D

i never got into arrays

Unless you do you will never become a successful code - they are an essential part of the syntax of any language. :)

upon reset of the timer after it has already expired, that the numbers remain red

However i am still uncertain how to start the timers at 0 aka RED

Setting $aTime elements to 0 will not do it as then the timer will not then count down - you need to reset the label each time (see the <<<<<<< lines in the script below): ;)

If the string is in a numerical value, how to i name it too

what if i did a picture

All you need to do is to add another label/pic control to the loop and use the data in a further array to fill it. I have used labels here to show you (look for the ********** lines)

#include <GUIConstants.au3>

; Set the HotKeys
HotKeySet("1", "rest1")
HotKeySet("2", "rest2")
HotKeySet("3", "rest3")
HotKeySet("4", "rest4")
HotKeySet("5", "rest5")
HotKeySet("6", "rest6")
HotKeySet("7", "rest7")

; Create some arrays to hold the variables
Global $aLabel[7], $aTime[7], $aLoop[7]
; This a 2d array - the first column holds the ControlIDs and the second the title for the label ++++++++++++++++++++++++++++++++++++++
Global $aTitle[7][2] =[[0, "Pie"], [0, "Chicken"], [0, "Noodle"], [0, "Chop Suey"], [0, "Chow Mein"], [0, "Biriyani"], [0, "Jalfrezi"]]

; Set the timer variables
$iStart_Mins = 60 ; in mins
$iRenew = 59
$iCheck_Time = TimerInit() ; This is used to change the time every second

$hGUI = GUICreate("Tray Warming Timer", 1000, 800, 0, 0)

GUISetFont(80, 400, 0, "MS Sans Serif")

; Loop
For $i = 0 To 6

    ; Create the labels, storing their controlIDs in the array
    $aLabel[$i] = GUICtrlCreateLabel("00:00", 1, 8 + (110 * $i), 300, 152) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlSetColor(-1, 0xFF0000)
    ; Now add the labels
    $aTitle[$i][0] = GUICtrlCreateLabel($aTitle[$i][1], 350, (110 * $i), 600, 152) ; ++++++++++++++++++++++++++++++++++++++++++
    GUICtrlSetColor(-1, 0x0000FF)
    ; And set the time delay in another array
    $aTime[$i] = $iStart_Mins * 60

Next

GUISetState()

; Set the top timer to 10 secs for testing <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$aTime[0] = 10

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Every second, run this section
    If TimerDiff($iCheck_Time) > 1000 Then
        ; Reset the timer to run this section
        $iCheck_Time = TimerInit()
        ; Loop through the arrays
        For $i = 0 To 6
            ; Remove a sec from the timer
            $aTime[$i] -= 1
            ; If the timer is below 0
            If $aTime[$i] < 0 Then
                ; Set the label to "Tray" in RED
                GUICtrlSetData($aLabel[$i], "Tray")
                GUICtrlSetColor($aLabel[$i], 0xFF0000)
            Else
                ; If not then set the label to the time remaining
                ; Note the use of StringFormat to get a leading 0 if required
                $iNew_Min = StringFormat("%02i", Floor($aTime[$i] / 60))
                $iNew_Sec = StringFormat("%02i", Mod($aTime[$i], 60))
                GUICtrlSetData($aLabel[$i], $iNew_Min & ":" & $iNew_Sec)
                GUICtrlSetColor($aLabel[$i], 0x00FF00) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            EndIf
        Next
    EndIf

WEnd

Func rest1()
    ; Reset the timer to the full value
    $aTime[0] = $iStart_Mins * 60
    GUICtrlSetData($aLabel[0], "00:00") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $aLoop[0] = 1 ;null marker
EndFunc   ;==>rest1

Func rest2()
    $aTime[1] = $iStart_Mins * 60
    GUICtrlSetData($aLabel[1], "00:00")
    $aLoop[1] = 1 ;null marker
EndFunc   ;==>rest2
Func rest3()
    $aTime[2] = $iStart_Mins * 60
    GUICtrlSetData($aLabel[2], "00:00")
    $aLoop[2] = 1 ;null marker
EndFunc   ;==>rest3
Func rest4()
    $aTime[3] = $iStart_Mins * 60
    GUICtrlSetData($aLabel[3], "00:00")
    $aLoop[3] = 1 ;null marker
EndFunc   ;==>rest4
Func rest5()
    $aTime[4] = $iStart_Mins * 60
    GUICtrlSetData($aLabel[4], "00:00")
    $aLoop[4] = 1 ;null marker
EndFunc   ;==>rest5
Func rest6()
    $aTime[5] = $iStart_Mins * 60
    GUICtrlSetData($aLabel[5], "00:00")
    $aLoop[5] = 1 ;null marker
EndFunc   ;==>rest6
Func rest7()
    $aTime[6] = $iStart_Mins * 60
    GUICtrlSetData($aLabel[6], "00:00")
    $aLoop[6] = 1 ;null marker
EndFunc   ;==>rest7

Does that meet yoru requirements? :graduated:

Make sure you read up an arrays - there is a good tutorial in the Wiki to start you on your way. And do feel free to ask questions if there is anything you do not understand - that is why we are here. ;)

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...