Sign in to follow this  
Followers 0
boniakowski

How to refresh info in $label variables in the GUI

4 posts in this topic

#1 ·  Posted (edited)

i have a problem refreshing the $label variable inside a gui. i was reading the forum but i dont understand if guictrlsetdata can help me and how.

this is my code:

#include <file.au3>

$file = ("C:\CAMARAWEB\general.log")
$fileLength = _FileCountLines($file)
$read1 = FileReadLine($file, $fileLength - 4)
$read2 = FileReadLine($file, $fileLength - 3)
$read3 = FileReadLine($file, $fileLength - 2)
$read4 = FileReadLine($file, $fileLength - 1)
$read5 = FileReadLine($file, $fileLength - 0)
;MsgBox(0,"",$read1)
;MsgBox(0,"",$read2)
;MsgBox(0,"",$read3)
;MsgBox(0,"",$read4)
;MsgBox(0,"",$read5)



#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=D:\TiemposTomdos.kxf
$Form1 = GUICreate("Form1", 615, 438, 272, 123)
$Titulo = GUICtrlCreateLabel("Ultimos Tiemos Tomados", 63, 24, 488, 54)
GUICtrlSetFont(-1, 26, 400, 0, "Arial Black")
$Tiempo5 = GUICtrlCreateLabel("Tiempo 5°: ", 63, 96, 121, 31)
GUICtrlSetFont(-1, 14, 400, 0, "Arial Black")
$Tiempo4 = GUICtrlCreateLabel("Tiempo 4°: ", 63, 133, 121, 31)
GUICtrlSetFont(-1, 14, 400, 0, "Arial Black")
$Tiempo3 = GUICtrlCreateLabel("Tiempo 3°: ", 63, 168, 121, 31)
GUICtrlSetFont(-1, 14, 400, 0, "Arial Black")
$Tiempo2 = GUICtrlCreateLabel("Tiempo 2°: ", 63, 205, 121, 31)
GUICtrlSetFont(-1, 14, 400, 0, "Arial Black")
$UltimoT = GUICtrlCreateLabel("Ultimo Tiempo: ", 159, 242, 282, 49)
GUICtrlSetFont(-1, 24, 400, 0, "Arial Black")
$Label1 = GUICtrlCreateLabel($read1, 187, 96, 121, 31)
GUICtrlSetFont(-1, 14, 400, 0, "Arial Black")
$Label2 = GUICtrlCreateLabel($read2, 187, 133, 121, 31)
GUICtrlSetFont(-1, 14, 400, 0, "Arial Black")
$Label3 = GUICtrlCreateLabel($read3, 187, 168, 121, 31)
GUICtrlSetFont(-1, 14, 400, 0, "Arial Black")
$Label4 = GUICtrlCreateLabel($read4, 187, 205, 121, 31)
GUICtrlSetFont(-1, 14, 400, 0, "Arial Black")
$Label5 = GUICtrlCreateLabel($read5, -1, 290, 557, 94)
GUICtrlSetFont(-1, 48, 400, 0, "Arial Black")
;GUICtrlSetColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1

If $read1 <= "00:00:30" Then
    MsgBox(0,"","es INFERIOR A 30 SEGUNDOS",2)
    GUICtrlSetColor($Label1, 0x80FF00)
Else
    GUICtrlSetColor($Label1, 0xFF0000)
    MsgBox(0,"","SUPERO EL TIEMPO ESTIMADO",2)
EndIf

If $read2 <= "00:00:30" Then
    MsgBox(0,"","es INFERIOR A 30 SEGUNDOS",2)
    GUICtrlSetColor($Label2, 0x80FF00)
Else
    GUICtrlSetColor($Label2, 0xFF0000)
    MsgBox(0,"","SUPERO EL TIEMPO ESTIMADO",2)
EndIf

If $read3 <= "00:00:30" Then
    MsgBox(0,"","es INFERIOR A 30 SEGUNDOS",2)
    GUICtrlSetColor($Label3, 0x80FF00)
Else
    GUICtrlSetColor($Label3, 0xFF0000)
    MsgBox(0,"","SUPERO EL TIEMPO ESTIMADO",2)
EndIf

If $read4 <= "00:00:30" Then
    MsgBox(0,"","es INFERIOR A 30 SEGUNDOS",2)
    GUICtrlSetColor($Label4, 0x80FF00)
Else
    GUICtrlSetColor($Label4, 0xFF0000)
    MsgBox(0,"","SUPERO EL TIEMPO ESTIMADO",2)
EndIf

If $read5 <= "00:00:30" Then
    MsgBox(0,"","es INFERIOR A 30 SEGUNDOS",2)
    GUICtrlSetColor($Label5, 0x80FF00)
Else
    GUICtrlSetColor($Label5, 0xFF0000)
    MsgBox(0,"","SUPERO EL TIEMPO ESTIMADO",2)
EndIf

 
WEnd


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

and this is the content of my file general.log in working dir c:camaraweb

00:00:01
00:00:02
00:00:03
00:00:04
00:00:05
00:00:06
00:00:17
00:00:08
00:00:09
00:00:23
00:00:53
11:00:03
01:00:03
00:50:00
00:50:00
00:51:00
00:50:00
00:00:23
 
the file general.log its constantly writing a new line in the last and the script read the last five lines and i need to refresh that info in $labels in the gui, and the gui never close its always showing the info readed.
 
any help is welcome
 
many thanks.
Christian
Edited by boniakowski

Share this post


Link to post
Share on other sites



boniakowski,

I would take a slightly different approach: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

$sFile = ("general.log")

Global $aLabel[5]                   ; An Array to hold label ControlIDs
Global $iPreviousFileSize = 0       ; Placeholder to ensure initial fill
Global $aLines                      ; Array to hold lines of file

; Create GUI
$Form1 = GUICreate("Form1", 615, 438, 272, 123)

; Create text labels - no need to store returned ControlID as they are never changed
GUICtrlCreateLabel("Ultimos Tiemos Tomados", 63, 24, 488, 54)
GUICtrlCreateLabel("Tiempo 5°: ", 63, 96, 121, 31)
GUICtrlCreateLabel("Tiempo 4°: ", 63, 133, 121, 31)
GUICtrlCreateLabel("Tiempo 3°: ", 63, 168, 121, 31)
GUICtrlCreateLabel("Tiempo 2°: ", 63, 205, 121, 31)
GUICtrlCreateLabel("Ultimo Tiempo: ", 159, 242, 282, 49)

; Create labels that will be changed
For $i = 0 To 3
    $aLabel[$i] = GUICtrlCreateLabel("", 187, 96 + (34 * $i), 121, 31) ; Nice little algorithm to locate the labels
Next
; Create "odd label out"
$aLabel[4] = GUICtrlCreateLabel("", -1, 290, 557, 94)

GUISetState(@SW_SHOW)

While 1
    
    ; You need all the action to take place in the same loop
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Get current file size
    $iFileSize = FileGetSize($sFile)
    ; Check if file has changed in size
    If $iFileSize <> $iPreviousFileSize Then
        ; Set new file size
        $iPreviousFileSize = $iFileSize
        ; Read file into an aray
        _FileReadToArray($sFile, $aLines)
        ; Fill labels
        For $i = 0 To 4
            ; Set data
            $sValue = $aLines[$aLines[0] - (4 - $i)] ; Again a little algorithm to get the data into the right labels
            GUICtrlSetData($aLabel[$i], $sValue)
            ; Check time - convert to seconds first
            If (StringMid($sValue, 1, 2) * 3600) + (StringMid($sValue, 4, 2) * 60) + StringMid($sValue, 6, 2) > 30 Then
                GUICtrlSetColor($aLabel[$i], 0xFF0000)
            Else
                GUICtrlSetColor($aLabel[$i], 0x80FF00)
            EndIf
        Next
    EndIf

WEnd
I hope the comments are clear enough, but please ask if you have any questions about what I have changed or why I have changed it. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

boniakowski,

I would take a slightly different approach: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

$sFile = ("general.log")

Global $aLabel[5]                   ; An Array to hold label ControlIDs
Global $iPreviousFileSize = 0       ; Placeholder to ensure initial fill
Global $aLines                      ; Array to hold lines of file

; Create GUI
$Form1 = GUICreate("Form1", 615, 438, 272, 123)

; Create text labels - no need to store returned ControlID as they are never changed
GUICtrlCreateLabel("Ultimos Tiemos Tomados", 63, 24, 488, 54)
GUICtrlCreateLabel("Tiempo 5°: ", 63, 96, 121, 31)
GUICtrlCreateLabel("Tiempo 4°: ", 63, 133, 121, 31)
GUICtrlCreateLabel("Tiempo 3°: ", 63, 168, 121, 31)
GUICtrlCreateLabel("Tiempo 2°: ", 63, 205, 121, 31)
GUICtrlCreateLabel("Ultimo Tiempo: ", 159, 242, 282, 49)

; Create labels that will be changed
For $i = 0 To 3
    $aLabel[$i] = GUICtrlCreateLabel("", 187, 96 + (34 * $i), 121, 31) ; Nice little algorithm to locate the labels
Next
; Create "odd label out"
$aLabel[4] = GUICtrlCreateLabel("", -1, 290, 557, 94)

GUISetState(@SW_SHOW)

While 1
    
    ; You need all the action to take place in the same loop
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Get current file size
    $iFileSize = FileGetSize($sFile)
    ; Check if file has changed in size
    If $iFileSize <> $iPreviousFileSize Then
        ; Set new file size
        $iPreviousFileSize = $iFileSize
        ; Read file into an aray
        _FileReadToArray($sFile, $aLines)
        ; Fill labels
        For $i = 0 To 4
            ; Set data
            $sValue = $aLines[$aLines[0] - (4 - $i)] ; Again a little algorithm to get the data into the right labels
            GUICtrlSetData($aLabel[$i], $sValue)
            ; Check time - convert to seconds first
            If (StringMid($sValue, 1, 2) * 3600) + (StringMid($sValue, 4, 2) * 60) + StringMid($sValue, 6, 2) > 30 Then
                GUICtrlSetColor($aLabel[$i], 0xFF0000)
            Else
                GUICtrlSetColor($aLabel[$i], 0x80FF00)
            EndIf
        Next
    EndIf

WEnd
I hope the comments are clear enough, but please ask if you have any questions about what I have changed or why I have changed it. :)

M23

 

 

MM i don´t understand, i must take more time to analize this, it´s some acomplish.

another perspective it´s welcome.

:sweating:

Share this post


Link to post
Share on other sites

boniakowski,

As I said, please ask if you have any questions. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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