Jump to content

Auto refresh label in GUI


Swe-Anders
 Share

Go to solution Solved by bobomb,

Recommended Posts

Hey guys! First topic I've created - hope I do everything right :)

I feel silly for not knowing this. I've made a farily large auto installer with some special functions (script is 1500 lines). This is something I've learnt thourh wiki-pages, youtube and the help-pages.

However, I'm really stuck and I can't seem to google myself out of this problem - even though I guess it's quite simple.

I want a label that is GREEN and says "Access OK" when I have read access to a folder... I do this by checking a value in an .ini-file at the folder path. And I want it to turn RED and say "Access missing" when it can't read the value in the .ini-file.

 

The important parts in this script would be:

Global $Access = IniRead('PATH\FILE.ini', 'Access', 'Yes', 'ERROR')

And then further down:

Global $Label21 = GUICtrlCreateLabel("Access", 10, 10, 275, 20)
GUICtrlSetFont(-1, 11, 800, 0, "Calibri")
   If $Access = "1" Then
      GUICtrlSetData($Label21, "Access OK")
      GUICtrlSetColor($Label21, 0x32CD32)
   Else
      GUICtrlSetData($Label21, "Access missing")
         GUICtrlSetColor($Label21, 0xFF0000)
   EndIf

 

Everything is working fine (when I start the program) but this script is ofcourse not auto-refreshing... I would like it to auto-refresh every second (without having to push a button to refresh) - so that the label would turn GREEN when I get access (even though I had no access when starting the program).

Thank you very much! :)

image.thumb.png.f7a281e6428dfeebd1b909b89232cb50.png

 

 

Link to comment
Share on other sites

You could use AdLibRegister for example:

#include <GUIConstantsEx.au3>

;~ Global Access Label Control Id Variable
Global $idAccess

;~ Global $bAccessGet (boolean)
;~ Get Access result
;~ 1 Successful (default) or see nb below.
;~ 0 Failure
;~ nb: You could use something like, the following which uses terinary to check if the file equals 'Yes' and set the variable to 1 else 0
;~ Global $bAccessGet = IniRead('PATH\FILE.ini', 'Access', 'Yes', 'ERROR') = 'Yes' ? 1 : 0
Global $bAccessGet = 1

;~ $bAccessSet (boolean)
;~ Check if label has changed, this will stop flickering of the label
;~ 1 = Access label already been set
;~ 0 = Access label has been changed
;~ nb: The initial configuration should be the opposite of $bAccessGet
$bAccessSet = $bAccessGet = 1 ? 0 : 1

Example()

Func Example()
    GUICreate("Example", 400, 35)
    $idAccess = GUICtrlCreateLabel("Access", 10, 10, 275, 20)
    Local $idExample = GUICtrlCreateButton("Change Access", 285, 8, 100, 20)
    GUICtrlSetFont(-1, 11, 800, 0, "Calibri")
    GUISetState(@SW_SHOW)
    ;~ Checks to see if $bAccessSet has been changed every 250 ms
    AdlibRegister("_CheckAccess")
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idExample
                $bAccessGet = $bAccessGet = 0 ? 1 : 0
        EndSwitch
    WEnd
    GUIDelete()
EndFunc

Func _CheckAccess()
    ;~ Check if $bAccessGet equals $bAccessSet
    ;~ True = Return, already set
    ;~ False = Update the label
    If $bAccessSet = $bAccessGet Then Return
    ;~ Update the label
    If $bAccessGet Then
        GUICtrlSetData($idAccess, "Access OK")
        GUICtrlSetColor($idAccess, 0x32CD32)
    Else
        GUICtrlSetData($idAccess, "Access missing")
        GUICtrlSetColor($idAccess, 0xFF0000)
    EndIf
    ;~ Update $bAccessSet with $bAccessGet value
    $bAccessSet = $bAccessGet
EndFunc

 

Edited by Subz
Link to comment
Share on other sites

On 12/4/2021 at 3:58 PM, Swe-Anders said:

Hey guys! First topic I've created - hope I do everything right :)

I feel silly for not knowing this. I've made a farily large auto installer with some special functions (script is 1500 lines). This is something I've learnt thourh wiki-pages, youtube and the help-pages.

However, I'm really stuck and I can't seem to google myself out of this problem - even though I guess it's quite simple.

I want a label that is GREEN and says "Access OK" when I have read access to a folder... I do this by checking a value in an .ini-file at the folder path. And I want it to turn RED and say "Access missing" when it can't read the value in the .ini-file.

 

The important parts in this script would be:

Global $Access = IniRead('PATH\FILE.ini', 'Access', 'Yes', 'ERROR')

And then further down:

Global $Label21 = GUICtrlCreateLabel("Access", 10, 10, 275, 20)
GUICtrlSetFont(-1, 11, 800, 0, "Calibri")
   If $Access = "1" Then
      GUICtrlSetData($Label21, "Access OK")
      GUICtrlSetColor($Label21, 0x32CD32)
   Else
      GUICtrlSetData($Label21, "Access missing")
         GUICtrlSetColor($Label21, 0xFF0000)
   EndIf

 

Everything is working fine (when I start the program) but this script is ofcourse not auto-refreshing... I would like it to auto-refresh every second (without having to push a button to refresh) - so that the label would turn GREEN when I get access (even though I had no access when starting the program).

Thank you very much! :)

image.thumb.png.f7a281e6428dfeebd1b909b89232cb50.png

 

 

i hope this help ya!

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 463, 318, 192, 114)
$Label21 = GUICtrlCreateLabel("Label1", 104, 72, 36, 17)
$Button1 = GUICtrlCreateButton("Button1", 128, 128, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
 Local Const $sFilePath = 'PATH\FILE.INI'
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button1
              Local $Access = IniRead($sFilePath, 'Access', 'Yes', 'ERROR')
            GUICtrlSetFont($Label21, 11, 800, 0, "Calibri")
   If $Access = "1" Then
      GUICtrlSetData($Label21, "Access OK")
      GUICtrlSetColor($Label21, 0x32CD32)
   Else
      GUICtrlSetData($Label21, "Access missing")
         GUICtrlSetColor($Label21, 0xFF0000)
   EndIf
    EndSwitch
WEnd

 

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

Link to comment
Share on other sites

2 hours ago, ad777 said:

i hope this help ya!

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 463, 318, 192, 114)
$Label21 = GUICtrlCreateLabel("Label1", 104, 72, 36, 17)
$Button1 = GUICtrlCreateButton("Button1", 128, 128, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
 Local Const $sFilePath = 'PATH\FILE.INI'
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button1
              Local $Access = IniRead($sFilePath, 'Access', 'Yes', 'ERROR')
            GUICtrlSetFont($Label21, 11, 800, 0, "Calibri")
   If $Access = "1" Then
      GUICtrlSetData($Label21, "Access OK")
      GUICtrlSetColor($Label21, 0x32CD32)
   Else
      GUICtrlSetData($Label21, "Access missing")
         GUICtrlSetColor($Label21, 0xFF0000)
   EndIf
    EndSwitch
WEnd

 

Thanks, but this won't auto update what I can see - which I need it to do :)

Link to comment
Share on other sites

On 12/4/2021 at 4:17 PM, Subz said:

You could use AdLibRegister for example:

#include <GUIConstantsEx.au3>
Global $idAccess, $bAccess = 1, $iAccess = 0

Example()

Func Example()
    GUICreate("Example", 400, 35)
    $idAccess = GUICtrlCreateLabel("Access", 10, 10, 275, 20)
    Local $idExample = GUICtrlCreateButton("Change Access", 285, 8, 100, 20)
    GUICtrlSetFont(-1, 11, 800, 0, "Calibri")
    GUISetState(@SW_SHOW)
    AdlibRegister("_CheckAccess")
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idExample
                $bAccess = $bAccess = 0 ? 1 : 0
        EndSwitch
    WEnd
    GUIDelete()
EndFunc

Func _CheckAccess()
    ;~ Check if access has changed
    If $iAccess = $bAccess Then Return
    ;~ Access has changed
    If $bAccess = "1" Then
        GUICtrlSetData($idAccess, "Access OK")
        GUICtrlSetColor($idAccess, 0x32CD32)
    Else
        GUICtrlSetData($idAccess, "Access missing")
        GUICtrlSetColor($idAccess, 0xFF0000)
    EndIf
    $iAccess = $bAccess
EndFunc

 

Thanks! I guess this is really what I need to do! But I've looked into your codes above and I must say that I'm confused to how I should implement it to my script. As I said, even though I've done a farily large script, I would still call myself a newbie :) But I will try and read it again, and I'll try to find some guides for AdlibRegister, and I'll try to implement your code above - and if I have no success, I will type here again and see if you would like to help me a bit more!

 

Thanks mate!

Link to comment
Share on other sites

1 hour ago, Subz said:

Updated the code above with comments, hope it makes sense.  Basically AdlibRegister will run a function that you can use to check for changes every xxx ms (default 250 ms), once detected you can then update your label.

Thank you so much. But I guess I'm not smart enough to understand anyway. I've read it 10 times and tried to implement it in my code - but it doesn't seem to do what I want :(

I have simplified my code (gone from 1500 rows to like 45 rows). Is there any way you could modify it to work for me? I really don't like asking for that, since I would like to learn... But hopefully I will understand once it's modified.

So if the user can read the INI-file ("C:\file.ini" in the code below) I would like it to be "Access OK" - and if not it should be "Access missing". And it needs to be auto refreshed.

Would this be too much to ask for? Thank you in advance :)

PS. I really like that you've considered the flickering in your code! That sounds great :)

#RequireAdmin
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#include <TrayConstants.au3>
#include <ColorConstants.au3>

#Region ### START Koda GUI section ### Form=
Global $Form1_1 = GUICreate("PROGRAM INSTALLER", 1300, 637, -1, -1)
Global $Button1 = GUICtrlCreateButton("INSTALL SELECTED", 16, 476, 155, 25)
Global $Form1_1_AccelTable[2][2] = [["^+{NUM 5}"]]
GUISetAccelerators($Form1_1_AccelTable)
GUISetState(@SW_SHOW)

; PROGRAMS TO SELECT FROM
Global $Checkbox101 = GUICtrlCreateCheckbox("Program 1", 16, 80, 105, 17)

; TEXT IN THE TOP LEFT CORNER TO BE AUTO-REFRESHED. TO TELL IF THE USER HAS ACCESS TO A SPECIFIC FOLDER - BY READING AN INI-FILE IN THAT FOLDER!
Global $Access = IniRead('C:\file.ini', 'HasAccess', 'Yes', 'Error no access.')
Global $Label21 = GUICtrlCreateLabel("Access", 50, 10, 275, 20)
   If $Access = "1" Then
      GUICtrlSetData($Label21, "Access OK")
   Else
      GUICtrlSetData($Label21, "Access missing")
   EndIf
#EndRegion ### END Koda GUI section ###


While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
      Case $Button1
         ; INSTALL PROGRAM 1
         If GUICtrlRead ($Checkbox101) = 1 Then
               RunWait ('msiexec.exe /i "C:\Setup 203.msi" /passive')
         EndIf
    EndSwitch
WEnd

 

Edited by Swe-Anders
Link to comment
Share on other sites

34 minutes ago, Subz said:

Not entirely sure how your code works, if C:\File.ini doesn't exist (could use If FileExists("C:\File.ini") Then...) when would C:\File.ini be created?

The ini-file is actually just an ini-file on a G:-folder (a network drive). So it's never really created within the script.

But yeah sure, for this code actually I could use "if file exist" (but I have other functions that needs to read the ini-file).

So you could, for this example, change that ini-read to "IfFileExists" or "If 1+1=2" :) The ini-file part is working good for me so :)

Edited by Swe-Anders
Link to comment
Share on other sites

Normally I would just check if the file exists and then use IniRead afterwards, something like:
If C:\File.ini is missing it will show missing, if you copy File.ini into C:\ then it should show Access OK.

#RequireAdmin
#include <GUIConstantsEx.au3>

;~ Global $bAccessGet (boolean)
;~ Get Access result
;~ 1 Successful (default) or see nb below.
;~ 0 Failure
Global  $bAccessGet = FileExists('C:\FILE.ini') ? 1 : 0

;~ $bAccessSet (boolean)
;~ Check if label has changed, this will stop flickering of the label
;~ 1 = Access label already been set
;~ 0 = Access label has been changed
;~ nb: The initial configuration should be the opposite of $bAccessGet
Global $bAccessSet = $bAccessGet = 1 ? 0 : 1

Global $Form1_1 = GUICreate("PROGRAM INSTALLER", 1300, 637, -1, -1)
Global $Button1 = GUICtrlCreateButton("INSTALL SELECTED", 16, 476, 155, 25)
Global $Label21 = GUICtrlCreateLabel("Access", 50, 10, 275, 20)
    _CheckAccess()

Global $Checkbox101 = GUICtrlCreateCheckbox("Program 1", 16, 80, 105, 17)

Global $Form1_1_AccelTable[2][2] = [["^+{NUM 5}"]]
GUISetAccelerators($Form1_1_AccelTable)

GUISetState(@SW_SHOW)

;~ Checks to see if $bAccessSet has been changed every 250 ms
   AdlibRegister("_CheckAccess")

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
      Case $Button1
         ; INSTALL PROGRAM 1
         If GUICtrlRead ($Checkbox101) = 1 Then
               RunWait ('msiexec.exe /i "C:\Setup 203.msi" /passive')
         EndIf
    EndSwitch
WEnd

Func _CheckAccess()
    $bAccessGet = FileExists('C:\FILE.ini') ? 1 : 0
    ;~ Check if $bAccessGet equals $bAccessSet
    ;~ True = Return, already set
    ;~ False = Update the label
    If $bAccessSet = $bAccessGet Then Return
    ;~ Update the label
    If $bAccessGet Then
        GUICtrlSetData($Label21, "Access OK")
        GUICtrlSetColor($Label21, 0x32CD32)
    Else
        GUICtrlSetData($Label21, "Access missing")
        GUICtrlSetColor($Label21, 0xFF0000)
    EndIf
    ;~ Update $bAccessSet with $bAccessGet value
    $bAccessSet = $bAccessGet
EndFunc

 

Link to comment
Share on other sites

I am also new, but in the area of checking if an INI exists or not, couldn't you just check to see if the default value was loaded when using IniRead to accomplish this?

And put IniRead in a loop until the default value changes? (The default value being set to something you know you wont find in your ini file)?

Edited by bobomb
Link to comment
Share on other sites

  • Solution

This is ugly but it works, I have the INI file set in the same dir as the au3

#RequireAdmin
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#include <TrayConstants.au3>
#include <ColorConstants.au3>

#Region ### START Koda GUI section ### Form=
Global $Form1_1 = GUICreate("PROGRAM INSTALLER", 1300, 637, -1, -1)
Global $Button1 = GUICtrlCreateButton("INSTALL SELECTED", 16, 476, 155, 25)
Global $Form1_1_AccelTable[2][2] = [["^+{NUM 5}"]]
GUISetAccelerators($Form1_1_AccelTable)
GUISetState(@SW_SHOW)

; PROGRAMS TO SELECT FROM
Global $Checkbox101 = GUICtrlCreateCheckbox("Program 1", 16, 80, 105, 17)
; TEXT IN THE TOP LEFT CORNER TO BE AUTO-REFRESHED. TO TELL IF THE USER HAS ACCESS TO A SPECIFIC FOLDER - BY READING AN INI-FILE IN THAT FOLDER!
Global $AccessKnown = 0, $iniValue, $Label21 = GUICtrlCreateLabel("Access", 50, 10, 275, 20)
GUICtrlSetData($Label21, "Access missing")
#EndRegion ### END Koda GUI section ###


While 1
    If $AccessKnown = 0 Then
        $iniValue = IniRead(@WorkingDir & '\file.ini', 'Access', 'Connection', 'No')
        If Not ($iniValue = 'No') Then
            GUICtrlSetData($Label21, "Access Granted")
            $AccessKnown = 1
        EndIf
    EndIf
    If $AccessKnown = 1 Then
        $iniValue = IniRead(@WorkingDir & '\file.ini', 'Access', 'Connection', 'No')
        If $iniValue = 'No' Then
            GUICtrlSetData($Label21, "Access Missing")
            $AccessKnown = 0
        EndIf
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
      Case $Button1
         ; INSTALL PROGRAM 1
         If GUICtrlRead ($Checkbox101) = 1 Then
               RunWait ('msiexec.exe /i "C:\Setup 203.msi" /passive')
         EndIf
   EndSwitch
WEnd

Test INI File Is called File.ini and contains:

[Access]
Connection=Yes

If you rename the file to something else while the script is running you will "lose access" also if you change the value inside to "No" you will lose access, if you rename it back you will "gain access" the value inside can be anything other than the string "No" as long as it exists even an empty string (e.g. Connection=) <== Would have access too.

Like I said, I am new to AutoIT3 so I am sure this is probably not the best way.. And the others might be able to explain why..

You can even add counters $a=$a +1 and when a hits 1000 or whatever you can run the IniRead if you dont want to hit the system with all those reads.. I would say my way is probably a last resort though but I'll wait to see what the experts say ;) I am also just noticing that this is nearly identical to what @ad777 previously posted for you but it looks like he was trying to avoid the loop probably because its bad form.

Edited by bobomb
Link to comment
Share on other sites

Thank you to both of you!

I continued with the recommendation from "bobomb" since my small brain understood that script better :) It seems to work just fine. It might lag a bit, but that's probably since the file I am reading from is only accessible with my VPN connected, so that might be why.

Posting a part of the script down below :) Really appreciated both of you taking your time to help me!

 

Global $AccessKnown = 0, $iniValue, $Label21 = GUICtrlCreateLabel("Checking access", 50, 10, 275, 20)
GUICtrlSetFont(-1, 11, 800, 0, "Calibri")
$IconAccess = GUICtrlCreateIcon("shell32.dll", 323, 10, 1)
Sleep(500)
#EndRegion ### END Koda GUI section ###


While 1
Global $iniAccess = IniRead('\\z30ar1cfvs010\brandapp$\Installation\Brand.ini', 'Access', 'Connection', 'Missing')
  If $AccessKnown = 0 Then
        If Not ($iniAccess = 'Missing') Then
            GUICtrlSetData($Label21, "Access OK")
            GUICtrlSetColor($Label21, 0x32CD32)
            GUICtrlSetImage($IkonAccess, "shell32.dll", 16802)
            $AccessKnown = 1
        EndIf
    EndIf
    If $AccessKnown = 1 Then
        If $iniAccess = 'Missing' Then
            GUICtrlSetData($Label21, "Access missing")
            GUICtrlSetColor($Label21, 0xFF0000)
            GUICtrlSetImage($IkonAccess, "shell32.dll", 200)
            $AccessKnown = 0
        EndIf
   EndIf
Edited by Swe-Anders
Link to comment
Share on other sites

  • Developers
3 minutes ago, Luke94 said:

I'd recommend throwing a small Sleep in that While loop. Your CPU will be maxed out otherwise.

Nah, you don't want that assuming the GuiGetMsg() is still in that loop giving the 10msecs pause already. ;) 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

@Swe-Anders you can (and probably should) slow down the INI reads a bit.

Global $AccessKnown = 0, $ReadInterval = 0, $iniValue, $Label21 = GUICtrlCreateLabel("Checking access", 50, 10, 275, 20)
GUICtrlSetFont(-1, 11, 800, 0, "Calibri")
$IconAccess = GUICtrlCreateIcon("shell32.dll", 323, 10, 1)
Sleep(500)
#EndRegion ### END Koda GUI section ###


While 1
    $ReadInterval = $ReadInterval + 1
    If $ReadInterval >= 200 Then ; Set your desired INI read interval here, 100 = Every 1 second
        Global $iniAccess = IniRead('\\z30ar1cfvs010\brandapp$\Installation\Brand.ini', 'Access', 'Connection', 'Missing')
        If $AccessKnown = 0 Then
            If Not ($iniAccess = 'Missing') Then
                GUICtrlSetData($Label21, "Access OK")
                GUICtrlSetColor($Label21, 0x32CD32)
                GUICtrlSetImage($IkonAccess, "shell32.dll", 16802)
                $AccessKnown = 1
                $ReadInterval = 0
            EndIf
        EndIf
        If $AccessKnown = 1 Then
            If $iniAccess = 'Missing' Then
                GUICtrlSetData($Label21, "Access missing")
                GUICtrlSetColor($Label21, 0xFF0000)
                GUICtrlSetImage($IkonAccess, "shell32.dll", 200)
                $AccessKnown = 0
                $ReadInterval = 0
            EndIf
        EndIf
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ; INSTALL PROGRAM 1
            If GUICtrlRead($Checkbox101) = 1 Then
                RunWait('msiexec.exe /i "C:\Setup 203.msi" /passive')
            EndIf
    EndSwitch
WEnd

This skips over the read loop until the set interval.. Still ugly, and it adds a global which is not ideal, but as far as testing goes you will be able to tell if too many INI reads were causing the delay or if it is the VPN(network) speed.. I would assume even setting it to something as low as 50 would benefit performance, but the higher you are willing to deal with the better..

You could also break out the access check into its own function (which I am learning myself is good form)

Global $AccessKnown = 0, $iniValue, $Label21 = GUICtrlCreateLabel("Checking access", 50, 10, 275, 20)
GUICtrlSetFont(-1, 11, 800, 0, "Calibri")
$IconAccess = GUICtrlCreateIcon("shell32.dll", 323, 10, 1)
Sleep(500)
#EndRegion ### END Koda GUI section ###

While 1
    $ReadInterval = $ReadInterval + 1
    If $ReadInterval >= 100 Then ; Set your desired INI read interval here, 100 = Every 1 second
        AccessMonitor()
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ; INSTALL PROGRAM 1
            If GUICtrlRead($Checkbox101) = 1 Then
                RunWait('msiexec.exe /i "C:\Setup 203.msi" /passive')
            EndIf
    EndSwitch
WEnd

Func AccessMonitor()
    Local $iniAccess = IniRead('\\z30ar1cfvs010\brandapp$\Installation\Brand.ini', 'Access', 'Connection', 'Missing'), $IkonAccess
    If $AccessKnown = 0 Then
        If Not ($iniAccess = 'Missing') Then
            GUICtrlSetData($Label21, "Access OK")
            GUICtrlSetColor($Label21, 0x32CD32)
            GUICtrlSetImage($IkonAccess, "shell32.dll", 16802)
            $AccessKnown = 1
            $ReadInterval = 0
        Else
            GUICtrlSetData($Label21, "Access missing")
            GUICtrlSetColor($Label21, 0xFF0000)
            GUICtrlSetImage($IkonAccess, "shell32.dll", 200)
            $AccessKnown = 0
            $ReadInterval = 0
        EndIf
    EndIf
    If $AccessKnown = 1 Then
        If $iniAccess = 'Missing' Then
            GUICtrlSetData($Label21, "Access missing")
            GUICtrlSetColor($Label21, 0xFF0000)
            GUICtrlSetImage($IkonAccess, "shell32.dll", 200)
            $AccessKnown = 0
            $ReadInterval = 0
        EndIf
    EndIf
EndFunc   ;==>AccessMonitor

And then even further break down the function into more pieces...

Global $AccessKnown = 0, $ReadInterval = 0, $iniValue, $IkonAccess, $Label21 = GUICtrlCreateLabel("Checking access", 50, 10, 275, 20)
GUICtrlSetFont(-1, 11, 800, 0, "Calibri")
$IconAccess = GUICtrlCreateIcon("shell32.dll", 323, 10, 1)
Sleep(500)
#EndRegion ### END Koda GUI section ###

While 1
    AccessMonitor()
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ; INSTALL PROGRAM 1
            If GUICtrlRead($Checkbox101) = 1 Then
                RunWait('msiexec.exe /i "C:\Setup 203.msi" /passive')
            EndIf
    EndSwitch
WEnd

Func AccessMonitor()
    $ReadInterval = $ReadInterval + 1
    If $ReadInterval >= 100 Then ; Set your desired INI read interval here, 100 = Every 1 second
        Local $iniAccess = IniRead('\\z30ar1cfvs010\brandapp$\Installation\Brand.ini', 'Access', 'Connection', 'Missing')
        If $AccessKnown = 0 Then
            If Not ($iniAccess = 'Missing') Then
                AccessOK()
            Else
                AccessMissing()
            EndIf
        EndIf
        If $AccessKnown = 1 Then
            If $iniAccess = 'Missing' Then
                AccessMissing()
            EndIf
        EndIf
    EndIf
EndFunc   ;==>AccessMonitor

Func AccessOK()
    GUICtrlSetData($Label21, "Access OK")
    GUICtrlSetColor($Label21, 0x32CD32)
    GUICtrlSetImage($IkonAccess, "shell32.dll", 16802)
    $AccessKnown = 1
    $ReadInterval = 0
EndFunc   ;==>AccessOK

Func AccessMissing()
    GUICtrlSetData($Label21, "Access missing")
    GUICtrlSetColor($Label21, 0xFF0000)
    GUICtrlSetImage($IkonAccess, "shell32.dll", 200)
    $AccessKnown = 0
    $ReadInterval = 0
EndFunc   ;==>AccessMissing

 

Edited by bobomb
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...