Jump to content
HockeyFan

Help updating a variable in GUI Label

Recommended Posts

HockeyFan

Hello,

Can someone offer some guidance on how I can better update a variable in a GUI label?

In my script i have pre-defined a text message "$Message" which includes several variables.  One of those variables "$Masterversion" is updated based on the Case statement selected.  When I run the script, the $Masterversion variable is not updating with the GUICtrlSetData command when the GUI is displayed.  What do i need to do to update the $Message string with the new $Masterversion variable?

Here is my script...which has been simplified down to the bare bones to just show the issue.

;Script Start

$SoftwareA = "1.20"
$SoftwareB = "4.6"
$SoftwareC = "2.8"
$SoftwareD = "5.1"

_Software() ;Returns $Software value

_Check()

Exit

Func _Check()
    $InstalledVersion = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\keyname", "value")
    $Masterversion = ""
    $Message = "  This software is out of date!" & @CRLF & @CRLF & "       installed version...... " & $InstalledVersion & @CRLF & "       current version........ " & $Masterversion & @CRLF &  @CRLF & "  Please contact your system administrator"

    $GUIForm = GUICreate("", 597, 438+57, -1, -1,  BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
    GUISetBkColor(0x000000) ;Black
    $Label1 = GUICtrlCreateLabel("*** NOTICE ***", 27, 32, 550, 81, BitOR($SS_CENTER,$WS_BORDER,$WS_CLIPSIBLINGS), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
    GUICtrlSetFont(-1, 48, 800, 0, "Arial")
    GUICtrlSetColor(-1, 0xFF0000)   ;Red
    GUICtrlSetBkColor(-1, 0x000000) ;Black
    $Label2 = GUICtrlCreateLabel($Message, 27, 152, 550, 250, BitOR($WS_BORDER,$WS_CLIPSIBLINGS), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
    GUICtrlSetFont(-1, 14, 800, 0, "Arial")
    GUICtrlSetColor(-1, 0xFFFF00)   ;Yellow
    GUICtrlSetBkColor(-1, 0x000000) ;Black
    $Button1 = GUICtrlCreateButton("OK", 248, 368+57, 100, 50, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_PUSHLIKE))
    GUICtrlSetFont(-1, 16, 800, 0, "Arial")
    GUISetState(@SW_HIDE)

    GUICtrlSetOnEvent($Button1, "_UpdateProcess")

    Select
        Case $Software = "A"
            Local $String = StringInStr($SoftwareName, "XXXX")
            If $String <> 0 Then
                $Masterversion = $SoftwareA
                If $InstalledVersion < $SoftwareA Then
                    GUICtrlSetData($Label2, $Message)
                    GUISetState(@SW_SHOW, $GUIForm)
                EndIf
            EndIf

        Case $Software = "B"
            Local $String = StringInStr($SoftwareName, "XXXX")
            If $String <> 0 Then
                $Masterversion = $SoftwareB
                If $InstalledVersion < $SoftwareB Then
                    GUICtrlSetData($Label2, $Message)
                    GUISetState(@SW_SHOW, $GUIForm)
                EndIf
            EndIf

        Case $Software = "C"
            Local $String = StringInStr($SoftwareName, "XXXX")
            If $String <> 0 Then
                $Masterversion = $SoftwareC
                If $InstalledVersion < $SoftwareC Then
                    GUICtrlSetData($Label2, $Message)
                    GUISetState(@SW_SHOW, $GUIForm)
                EndIf
            EndIf
        Case $Software = "D"
            Local $String = StringInStr($SoftwareName, "XXXX")
            If $String <> 0 Then
                $Masterversion = $SoftwareD
                If $InstalledVersion < $SoftwareD Then
                    GUICtrlSetData($Label2, $Message)
                    GUISetState(@SW_SHOW, $GUIForm)
                EndIf
            EndIf
        Case $Software = "E"

        Case $Software = "F"

        Case $Software = "G"

        Case $Software = "H"

        Case $Software = "I"

        Case $Software = "J"

        Case $Software = "K"

        Case Else
            ;Display message
    EndSelect
    While 1
        Sleep(40)  ; Idle around
    WEnd
EndFunc

Share this post


Link to post
Share on other sites
JohnOne

First, you are testing strings against ints.

Second, you are testing strings like they were numbers.

Suggest you use 

$SoftwareA = 1.20
$SoftwareB = 4.6
$SoftwareC = 2.8
$SoftwareD = 5.1

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
HockeyFan

JohnOne,

Thanks for the reply.  Yes, I am testing strings like they are numbers because the "$InstalledVersion" variable pulled from the registry is a String Value. Not ideal, but that's what I'm working with.

Share this post


Link to post
Share on other sites
JohnOne

You should take my advice then and do your comparison like so...

If Number($InstalledVersion) < $SoftwareA Then
    GUICtrlSetData($Label2, $Message)
    GUISetState(@SW_SHOW, $GUIForm)
EndIf

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
HockeyFan

OK...I will give that a try.  Thanks for the help!  :)

Share this post


Link to post
Share on other sites
kylomas

Before you enter your select...case structure you might want to see what you are actually comparing by adding

consolewrite('$Software = ' & $Software & @CRLF)

before the 'Select' statement.

edit: spelling

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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

×