boniakowski Posted July 4, 2014 Share Posted July 4, 2014 (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: expandcollapse popup#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 July 4, 2014 by boniakowski Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 4, 2014 Moderators Share Posted July 4, 2014 boniakowski,I would take a slightly different approach: expandcollapse popup#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 WEndI 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
boniakowski Posted July 10, 2014 Author Share Posted July 10, 2014 boniakowski, I would take a slightly different approach: expandcollapse popup#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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 10, 2014 Moderators Share Posted July 10, 2014 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now