Jump to content
The-dude

GuiCtrlCreateLabel (File Read) Refresh after running script?

Recommended Posts

Hi Guys,

I have read only text in my gui being pulled from a text file and for some reason it's not refreshing after my script runs. 

$file = FileRead(@ScriptDir & "\temp.txt")
$control = GUICtrlCreateLabel($file, 8, 236, 220, 17)

Is there something I can put in there that allows my GUICtrlCreateLabel to refresh? I have input gui's that the user will need to add data to that I don't want clearing or changing. 

Thanks!

Share this post


Link to post
Share on other sites

You can use Adlibregister to check if the file has changed and update the label.

Share this post


Link to post
Share on other sites
Posted (edited)

Subz, would I have to create a function for that or would that live in the region area? Here's my script-

HotKeySet("{ESC}", "_Terminate")



#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#Region
$Form1_1 = GUICreate("A&K Testing", 235, 285, 430, 353)
$Input5 = GUICtrlCreateInput(@MON & "-" & @MDAY & "-" & @YEAR, 80, 24, 121, 21)
$DATE = GUICtrlCreateLabel("DATE", 40, 28, 33, 17)
$Input1 = GUICtrlCreateInput("", 80, 48, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE))
$Label1 = GUICtrlCreateLabel("TEST#", 40, 51, 39, 17)
$Input2 = GUICtrlCreateInput("", 80, 72, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE))
$Label2 = GUICtrlCreateLabel("TEMP", 40, 76, 34, 17)
$Input3 = GUICtrlCreateInput("", 80, 96, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE))
$Label3 = GUICtrlCreateLabel("PSI", 48, 100, 21, 17)
$Input4 = GUICtrlCreateInput("", 80, 120, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE))
$Label4 = GUICtrlCreateLabel("DWELL", 32, 123, 42, 17)
$Input7 = GUICtrlCreateInput("", 80, 144, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE))
$Label7 = GUICtrlCreateLabel("PLACEMENT", 8, 148, 69, 17)
$Label5 = GUICtrlCreateLabel("Created by ", 8, 264, 149, 17)
$Input6 = GUICtrlCreateInput("", 80, 168, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE))
$Label6 = GUICtrlCreateLabel("USER", 40, 172, 34, 17)


;$Label8 = GUICtrlCreateLabel("Last file name", 8, 240, 69, 17)
$file = FileRead(@ScriptDir & "\temp.txt")
$control = GUICtrlCreateLabel($file, 8, 236, 220, 17)

$Button1 = GUICtrlCreateButton("START TEST", 32, 201, 75, 25)
GUICtrlSetBkColor(-1, 0x00FF00)
$Button2 = GUICtrlCreateButton("STOP TEST", 128, 201, 75, 25)
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetBkColor(-1, 0xFF0000)

GUISetState(@SW_SHOW)
#EndRegion

While 1
     $nMsg = GUIGetMsg()
     Switch $nMsg
         Case $GUI_EVENT_CLOSE
              Exit
         Case $Button2
             Send("{F2}")
         Case $Button1
             If Guictrlread($Input1)="" Then
            MsgBox(0,"","You must enter a TEST NUMBER")
             Else
            If Guictrlread($Input2)="" Then
            MsgBox(0,"","You must enter a TEMP")
            Else
                    If Guictrlread($Input3)="" Then
            MsgBox(0,"","You must enter the PSI")
                    Else
            If Guictrlread($Input4)="" Then
            MsgBox(0,"","You must enter a dwell time")
            Else
                    If Guictrlread($Input5)="" Then
            MsgBox(0,"","You must enter today's date")
            Else
                If Guictrlread($Input6)="" Then
            MsgBox(0,"","You must enter your name in USER")
            Else
             If Guictrlread($Input7)="" Then
            MsgBox(0,"","You must enter a placement (e.g.-TOP, BOTOM, RIGHT, LEFT")
             Else

            $DataFromUser = "TEST{#}" & GUICtrlRead($Input1) & "_" & GUICtrlRead($Input2) & "_" & GUICtrlRead($Input3) & "_" & GUICtrlRead($Input4)& "_" & GUICtrlRead($Input5)& "_" & GUICtrlRead($Input7)& "_" & GUICtrlRead($Input6)
            $DataForFile = "TEST#" & GUICtrlRead($Input1) & "_" & GUICtrlRead($Input2) & "_" & GUICtrlRead($Input3) & "_" & GUICtrlRead($Input4)& "_" & GUICtrlRead($Input5)& "_" & GUICtrlRead($Input7)& "_" & GUICtrlRead($Input6)
            ;filedelete("temp.txt")
            $hFO = FileOpen("temp.txt", 2)
            FileWrite($hFO, "")
            FileClose($hFO)
            FileWrite("temp.txt",$DataForFile)
            ;FileOpen(@ScriptDir & "\TempFile.txt", 1)


            Run("Some stuff")
             WinWaitActive("Save As")
              Sleep(1000)
             Send($DataFromUser)
              Send("{Enter}")
             WinWaitClose("Save As")
             Send("!+{F4}",0)
                GUICtrlSetData($Input1, "")
                GUICtrlSetData($Input2, "")
                GUICtrlSetData($Input3, "")
                GUICtrlSetData($Input4, "")
                GUICtrlSetData($Input7, "")
            EndIf
            EndIf
            EndIf
            EndIf
            EndIf
            EndIf
            EndIf
EndSwitch
WEnd

Func _Terminate()
    Exit
EndFunc   ;==>_Terminate

 

Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites

The-dude,

When you post code in future please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. Thanks in advance for your cooperation.

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

 

Share this post


Link to post
Share on other sites

Here is an example that I was going to share, hopefully it explains how AdlibRegister works, after running the script, open the filename.ini file and add Label_02 = Something and save, the label 02 will update accordingly.

PS: When posting code can you use <> it just makes it easier to read.

#include <GUIConstantsEx.au3>

Global $g_sFileName = @ScriptDir & "\Filename.ini"
Global $g_idLabel_01, $g_idLabel_02

Example()

Func Example()
    If IniRead($g_sFileName, "Labels", "Label_01", "") == "" Then _CreateSampleIni($g_sFileName)
    GUICreate("Labels", 200, 60)
    $g_idLabel_01 = GUICtrlCreateLabel(IniRead($g_sFileName, "Labels", "Label_01", "Label_01 Key doesn't exist"), 10, 10, 180, 20)
    $g_idLabel_02 = GUICtrlCreateLabel(IniRead($g_sFileName, "Labels", "Label_02", "Label_02 Key doesn't exist"), 10, 30, 180, 20)

    GUISetState()

    AdlibRegister("_UpdateLabel") ;~ Checks every 250 ms by default

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc

Func _UpdateLabel()
    If IniRead($g_sFileName, "Labels", "Label_01", "Label_01 Key doesn't exist") <> GUICtrlRead($g_idLabel_01) Then
        GUICtrlSetData($g_idLabel_01, IniRead($g_sFileName, "Labels", "Label_01", "Label_01 Key doesn't exist"))
    EndIf
    If IniRead($g_sFileName, "Labels", "Label_02", "Label_02 Key doesn't exist") <> GUICtrlRead($g_idLabel_02) Then
        GUICtrlSetData($g_idLabel_02, IniRead($g_sFileName, "Labels", "Label_02", "Label_02 Key doesn't exist"))
    EndIf
EndFunc

Func _CreateSampleIni($_sFileName)
    IniWrite($g_sFileName, "Labels", "Label_01", "Label_01")
;~  IniWrite($g_sFileName, "Labels", "Label_01", "Label_02") ;~ Commented out for example
EndFunc

 

Share this post


Link to post
Share on other sites

Subz, I think it's been a long week... I'm totally trying to adapt the above example to my script but I'm not grasping how I would go about doing that. I was hoping for a quick and easy add without having to rework my already existing code. 

Appreciate the advice on posting code! Not sure why I thought it was automatically register that as code and format accordingly. 

 

Share this post


Link to post
Share on other sites

@The-dude Try:

HotKeySet("{ESC}", "_Terminate")



#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#Region
$Form1_1 = GUICreate("A&K Testing", 235, 285, 430, 353)
$Input5 = GUICtrlCreateInput(@MON & "-" & @MDAY & "-" & @YEAR, 80, 24, 121, 21)
$DATE = GUICtrlCreateLabel("DATE", 40, 28, 33, 17)
$Input1 = GUICtrlCreateInput("", 80, 48, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE))
$Label1 = GUICtrlCreateLabel("TEST#", 40, 51, 39, 17)
$Input2 = GUICtrlCreateInput("", 80, 72, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE))
$Label2 = GUICtrlCreateLabel("TEMP", 40, 76, 34, 17)
$Input3 = GUICtrlCreateInput("", 80, 96, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE))
$Label3 = GUICtrlCreateLabel("PSI", 48, 100, 21, 17)
$Input4 = GUICtrlCreateInput("", 80, 120, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE))
$Label4 = GUICtrlCreateLabel("DWELL", 32, 123, 42, 17)
$Input7 = GUICtrlCreateInput("", 80, 144, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE))
$Label7 = GUICtrlCreateLabel("PLACEMENT", 8, 148, 69, 17)
$Label5 = GUICtrlCreateLabel("Created by ", 8, 264, 149, 17)
$Input6 = GUICtrlCreateInput("", 80, 168, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE))
$Label6 = GUICtrlCreateLabel("USER", 40, 172, 34, 17)

;$Label8 = GUICtrlCreateLabel("Last file name", 8, 240, 69, 17)
$control = GUICtrlCreateLabel("", 8, 236, 220, 17)

$Button1 = GUICtrlCreateButton("START TEST", 32, 201, 75, 25)
GUICtrlSetBkColor(-1, 0x00FF00)
$Button2 = GUICtrlCreateButton("STOP TEST", 128, 201, 75, 25)
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetBkColor(-1, 0xFF0000)

GUISetState(@SW_SHOW)
#EndRegion
AdlibRegister("_UpdateLabel")
While 1
     $nMsg = GUIGetMsg()
     Switch $nMsg
         Case $GUI_EVENT_CLOSE
              Exit
         Case $Button2
             Send("{F2}")
         Case $Button1
            If Guictrlread($Input1)="" Then
                MsgBox(0,"","You must enter a TEST NUMBER")
            Else
                If Guictrlread($Input2)="" Then
                    MsgBox(0,"","You must enter a TEMP")
                Else
                    If Guictrlread($Input3)="" Then
                        MsgBox(0,"","You must enter the PSI")
                    Else
            If Guictrlread($Input4)="" Then
            MsgBox(0,"","You must enter a dwell time")
            Else
                    If Guictrlread($Input5)="" Then
            MsgBox(0,"","You must enter today's date")
            Else
                If Guictrlread($Input6)="" Then
            MsgBox(0,"","You must enter your name in USER")
            Else
             If Guictrlread($Input7)="" Then
            MsgBox(0,"","You must enter a placement (e.g.-TOP, BOTOM, RIGHT, LEFT")
             Else

            $DataFromUser = "TEST{#}" & GUICtrlRead($Input1) & "_" & GUICtrlRead($Input2) & "_" & GUICtrlRead($Input3) & "_" & GUICtrlRead($Input4)& "_" & GUICtrlRead($Input5)& "_" & GUICtrlRead($Input7)& "_" & GUICtrlRead($Input6)
            $DataForFile = "TEST#" & GUICtrlRead($Input1) & "_" & GUICtrlRead($Input2) & "_" & GUICtrlRead($Input3) & "_" & GUICtrlRead($Input4)& "_" & GUICtrlRead($Input5)& "_" & GUICtrlRead($Input7)& "_" & GUICtrlRead($Input6)
            ;filedelete("temp.txt")
            $hFO = FileOpen("temp.txt", 2)
            FileWrite($hFO, "")
            FileClose($hFO)
            FileWrite("temp.txt",$DataForFile)
            ;FileOpen(@ScriptDir & "\TempFile.txt", 1)


            Run("Some stuff")
             WinWaitActive("Save As")
              Sleep(1000)
             Send($DataFromUser)
              Send("{Enter}")
             WinWaitClose("Save As")
             Send("!+{F4}",0)
                GUICtrlSetData($Input1, "")
                GUICtrlSetData($Input2, "")
                GUICtrlSetData($Input3, "")
                GUICtrlSetData($Input4, "")
                GUICtrlSetData($Input7, "")
            EndIf
            EndIf
            EndIf
            EndIf
            EndIf
            EndIf
            EndIf
EndSwitch
WEnd

Func _UpdateLabel()
    Local $sFileRead = FileRead(@ScriptDir & "\temp.txt")
    If $sFileRead <> GUICtrlRead($control) Then
        GUICtrlSetData($control, $sFileRead)
    EndIf
EndFunc

Func _Terminate()
    Exit
EndFunc   ;==>_Terminate

 

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

×
×
  • Create New...