Jump to content

USMT 5 GUI Button Function error


LilleyBoy
 Share

Recommended Posts

Hello Everyone,

This Forum has been my home for the last 2 days but I'm hitting a brick wall and need some help.

I am creating a USMT front End GUI for my company which I originally scripted out in powershell a long time ago. It calls on 2 XML files also written by myself to determine the logic of the data backup. This part works flawlessly. (apart from my poor attempt at an array, but we will get to that)

I know USMT has been implemented into a GUI on the forums before and parts of it I have used in my script (the main argument calling etc) but USMT has moved on an now works very differently. I have also taken a very nice UDF called MTSkins but trouble lies in  getting what I originally had working in a test GUI to work with the new GUI, and more specifically it seems to be the main "Back-Up" button that kills the whole thing.

I started with Autoit on tuesday and am now pulling my hair out. I've been at it full on for the last 48 hours.

Func _CreateMenu1Content()
    GLOBAL $ScanState = GUICtrlCreateLabel("Specify the location to save the backup (type, browse, or drag path)", $GUI_MENUBKG_WIDTH+15, 40, 430, 23)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
    GLOBAL $SavePath = GUICtrlCreateInput("", $GUI_MENUBKG_WIDTH+15, 60, 430, 23)
        GUICtrlSetState($SavePath, $GUI_DROPACCEPTED)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
    GLOBAL $BrowseSavePath = GUICtrlCreateButton("...", $GUI_MENUBKG_WIDTH+450, 60, 20, 23)
    GLOBAL $UI = GUICtrlCreateLabel("Enter the Username (SSO) you want to backup.", $GUI_MENUBKG_WIDTH+15, 90, 250, 23)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
    GLOBAL $Name = GUICtrlCreateInput("", $GUI_MENUBKG_WIDTH+15, 110, 80, 23)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
    GLOBAL $MultipleUser = GUICtrlCreateCheckbox("All users logged in within the last 21 days",  $GUI_MENUBKG_WIDTH+100, 110, 400, 23)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
    GLOBAL $Cancel = GUICtrlCreateButton("Cancel", $GUI_MENUBKG_WIDTH+300, 290, 95, 32)
         GUICtrlSetColor(-1, 0xffffff)
         GUICtrlSetState($Cancel, $GUI_HIDE)
    GLOBAL $ShowTime = GUICtrlCreateLabel("", $GUI_MENUBKG_WIDTH+120, 130, 100, 15, $SS_RIGHT)
    GLOBAL $ShowSize = GUICtrlCreateLabel("", $GUI_MENUBKG_WIDTH+140, 150, 100, 15, $SS_RIGHT)
    GLOBAL $ProgressBar = GUICtrlCreateProgress($GUI_MENUBKG_WIDTH+180, 180, 370, 20)
        GUICtrlSetState($ProgressBar, $GUI_HIDE)
    GLOBAL $ProgressText = GUICtrlCreateLabel("", $GUI_MENUBKG_WIDTH+200, 203, 100, 15, $SS_RIGHT)
    GLOBAL $ShowWaitMessage = GUICtrlCreateLabel("Please  wait, setting up", $GUI_MENUBKG_WIDTH+220, 200, 110, 15)
        GUICtrlSetState($ShowWaitMessage, $GUI_HIDE)
    GLOBAL $ShowWaitMessageDots = GUICtrlCreateLabel($WaitMessageDots, $GUI_MENUBKG_WIDTH+250, 200, 200, 15)
        GUICtrlSetState($ShowWaitMessageDots, $GUI_HIDE)
    GLOBAL $ShowCurrentFile = GUICtrlCreateLabel("", $GUI_MENUBKG_WIDTH+10 , 200, 480, 15, $DT_END_ELLIPSIS)
    GLOBAL $AL = GUICtrlCreateLabel ("Please select the type of backup required.", $GUI_MENUBKG_WIDTH+15, 140, 300, 20)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
    GLOBAL $LogicFiles = GUICtrlCreateCombo ("", $GUI_MENUBKG_WIDTH+15, 165, 200, 200)
        GUICtrlSetData($LogicFiles, "Full Backup|Configuration backup")
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
    $Go = GUICtrlCreateButton("Back-Up", $GUI_MENUBKG_WIDTH+400, 290, 95, 32)
         GUICtrlSetColor(-1, 0xffffff)
         GUICtrlSetBkColor(-1, $GUI_FONT_COLOR)
    Local $AccelKeys[1][2] = [["{ENTER}", $Go]]
    GUISetAccelerators($AccelKeys)

    While 1
        GLOBAL $LogicFile = ""
                Switch GUICtrlRead($LogicFile)
            Case "Full Backup"
                $LogicFile = "config_XML\MigUserCustom.xml"
                ExitLoop
            Case "Configuration backup" ; Does not work as of 24/01
                $LogicFile = "config_XML\MigUserCustom_VOD.xml"
                Exitloop
        EndSwitch
    WEnd


        ; Build the Argument Variable
    If $LastState == 1 And GUICtrlRead($MultipleUser) == 4 Then
        GUICtrlSetState($Name, $GUI_Enable)
    EndIf
    If $LastState == 4 And GUICtrlRead($MultipleUser) == 1 Then
        GUICtrlSetState($Name, $GUI_DISABLE)
    EndIf



$MSG = GUIGetMsg()
    While 1
        Switch $MSG
                Case $Go
                Do
                    $GetName = StringUpper(StringReplace(GUICtrlRead($Name), "", "_"))
                    $GetSavePath = GUICtrlRead($SavePath)
                    If $GetName == "" And GUICtrlRead($MultipleUser) == 4 Then
                        MsgBox(16, "ERROR", "Please enter an SSO to backup OR select the ALL PROFILES option")
                                Else
                                    $Date = _NowCalcDate()
                                    $DateBreak = StringSplit($Date, "/")
                                    $FullSavePath = StringUpper(StringReplace($GetSavePath & "\" & $GetName & $DateBreak[2] & $DateBreak[3] & StringRight($DateBreak[1], 2), "\\", "\"))
                                If StringLeft($FullSavePath, 1) == "\" Then $FullSavePath = "\" & $FullSavePath
                                    $Exist = FileExists($FullSavePath)
                                Local $YesOrNo
                                If $Exist Then $YesOrNo = MsgBox(4, "Overwrite?", "The save path specified already exists:" & @CR & $FullSavePath & @CR & @CR & "Overwrite?")
                                If $YesOrNo == 6 Or Not $Exist Then
                                        $TempFile = _TempFile($FullSavePath)
                                        $TestTempFile = FileOpen($TempFile, 1 + 8)
                                        FileClose($TestTempFile)
                                        FileDelete($TempFile)
                                If $TestTempFile == -1 Then
                                        MsgBox(16, "ERROR", "The path you have specified does not exist or is not writable.  Please check the path.")
                                Else
                                        $StartTime = TimerInit()
                                        GUICtrlDelete($Go)
                                        GUICtrlSetState($Cancel, $GUI_SHOW)
                                        GUICtrlSetState($SavePath, $GUI_DISABLE)
                                        GUICtrlSetState($BrowseSavePath, $GUI_DISABLE)
                                        GUICtrlSetState($Name, $GUI_DISABLE)
                                        _BuildUSMTCommand($FullSavePath, $GetName)
                                EndIf
                                EndIf
                                EndIf
                    Until True == False
                        Case $BrowseSavePath
                    $Where = FileSelectFolder("Choose the location to save the data", "", 1 + 4)
                    GUICtrlSetData($SavePath, $Where)
            EndSwitch
    WEnd

EndFunc

This is the function as it looks now. Absolutely butchered by countless aimless attempts to try and fix it.

I have tried to put the code in a function, out a function (how it was originally working), through if statements, while loops and cases and nothing seems to work.

I have attached the full code if you want to reference.

P.S I am sure there are many more errors than mentioned above but my goal for this week is just to get the thing to run the backup. Any other help is greatly appreciated I am at wits end with the help File and cant help but think for a first attempt at Autoit I'm in way over my head.

Finally, I do have a working section of code elsewhere that runs in a very basic GUI if you think that would be helpful I can post that also.

USMT5GUI_Final.au3

Link to comment
Share on other sites

Well I didn't execute the code but got few comments that should be applied and you can then see if that solves your problem :

1- $MSG = GUIGetMsg() is outside the main loop, you will only get the first msg

2- do not declare variables (Local or Global) inside a loop, declare them before the loop or at the top of the function

3- comparator == is only for case sensitive strings comparaison, use = instead

4- your do loop, how do you exit from it (until True == False ?) --> I don't see any exitloop there !

5- Do not declare Global variables inside a function.  It makes debugging and readability very hard.

Edited by Nine
Link to comment
Share on other sites

Thanks nine for the quick reply.

Noted in regards to the global variables I can make that change tomorrow. The UDF i used was formatted in the same way and made the deletion of each page quick inside the function but will follow your guidelines and see how I get on.

As for the loop, originally I had an until True = False and that worked in the old GUI but doesnt in this one. I may have been messing around and forgot to change it back which could ruin further debugging attempts.

The MSG problem may be the one actually. I am still getting to grips with this concept I'll check out the help file....again and see if I can come up with something more robust and repost.

Forgive me. I'm pretty brain fried at the moment.

Link to comment
Share on other sites

Morning all from the UK.

Ready for another day to tackle this.

I followed your advice, moved the Global Variables to a more suitable location and moved the GUIGetMSG() to inside the while loop.

This is how it looks now but still no avail with the launch button that should kick of the final function.

;#GUI Handle/hWND & Buttons Handles/ControlIDs
Global $GUI_WHNDL=0
Global $GUI_CLOSEBTN=0, $GUI_MINIMIZEBTN=0

;#Menu Items
   Dim $MenuEntries[4]=["ScanState", "LoadState", "Help", "About"]
;#Flag for Over Detection (each Menu-Item above must have one)
   Global $OverFlag[4]=[False, False, False, False]

;#MENU INDEX VARS
   Global $MENU_CURR_INDEX=0    ;Current index of the menu (0=MenuItem1, 1=MenuItem2, etc...)
   Global $MENU_PREV_INDEX=0    ;Previous index of the menu (Store previous value of $MENU_CURR_INDEX)

;#Colors Settings
_MTSkin_GUISetSkin("Default")



#Region "GUI CREATION" ------------------------------------------------------------------------

   Local $Handles=_MTSkin_GUICreate("MTSkin_Example", $GUI_WIDTH, $GUI_HEIGHT, @DesktopWidth /2.95, @DesktopHeight /3.2)

   $GUI_WHNDL=$Handles[0]       ;_ $Handles[0] = "GUI windows handle"
   $GUI_CLOSEBTN=$Handles[1]    ;_ $Handles[1] = "Close button controlID"
   $GUI_MINIMIZEBTN=$Handles[2] ;_ $Handles[2] = "Minimize button controlID"

   Local $MenuItems=_MTSkin_GUICreateMenu($GUI_WHNDL, $MenuEntries, $GUI_MENUBKG_WIDTH, $TITLE, $SUBTITLE, $SUBTITLE2)
      ;_ $MenuItems[n] = "Array of the 'n" menu items controlID


   ;#Create Handles For Over Menu Items Detection (for each Menu-Item)
   Local $hOvrLblWnd[Ubound($MenuItems)]
   For $i=0 To Ubound($hOvrLblWnd)-1
      $hOvrLblWnd[$i] = ControlGetHandle(WinGetHandle($GUI_WHNDL), '', $MenuItems[$i])
   Next

   ;#Create some Sample Content (Function defined below)
   _InitContentOnStart()
   GUISetState(@SW_SHOW)

#EndRegion "GUI CREATION" ---------------------------------------------------------------------



While 1

    $tPoint = _WinAPI_GetMousePos()
    ;#==========================================#
    ;# Check if the cursor is over a menu item  #
    ;#==========================================#
    If _WinAPI_WindowFromPoint($tPoint) = $hOvrLblWnd[0] Then
        If Not $OverFlag[0] Then
            ConsoleWrite(' Over-Detection: Label1' & @CR)
            GUICtrlSetBkColor($MenuItems[0], $GUI_MENU_HOVER_COLOR)
            $OverFlag[0] = 1
        EndIf
    ElseIf _WinAPI_WindowFromPoint($tPoint) = $hOvrLblWnd[1] Then
        If Not $OverFlag[1] Then
            ConsoleWrite(' Over-Detection: Label2' & @CR)
            GUICtrlSetBkColor($MenuItems[1], $GUI_MENU_HOVER_COLOR)
            $OverFlag[1] = 1
        EndIf
    ElseIf _WinAPI_WindowFromPoint($tPoint) = $hOvrLblWnd[2] Then
        If Not $OverFlag[2] Then
            ConsoleWrite(' Over-Detection: Label3' & @CR)
            GUICtrlSetBkColor($MenuItems[2], $GUI_MENU_HOVER_COLOR)
            $OverFlag[2] = 1
        EndIf
    ElseIf _WinAPI_WindowFromPoint($tPoint) = $hOvrLblWnd[3] Then
        If Not $OverFlag[3] Then
            ConsoleWrite(' Over-Detection: Label4' & @CR)
            GUICtrlSetBkColor($MenuItems[3], $GUI_MENU_HOVER_COLOR)
            $OverFlag[3] = 1
        EndIf
    Else
       ;#========================================#
       ;# Check if focus is lost on a menu item  #
       ;#========================================#
        If $OverFlag[0] Then
            ConsoleWrite(' Focus-Loss: Label1' & @CR)
            GUICtrlSetBkColor($MenuItems[0], $GUI_MENU_COLOR)
            $OverFlag[0] = 0
        ElseIf $OverFlag[1] Then
            ConsoleWrite(' Focus-Loss: Label2' & @CR)
            GUICtrlSetBkColor($MenuItems[1], $GUI_MENU_COLOR)
            $OverFlag[1] = 0
        ElseIf $OverFlag[2] Then
            ConsoleWrite(' Focus-Loss: Label3' & @CR)
            GUICtrlSetBkColor($MenuItems[2], $GUI_MENU_COLOR)
            $OverFlag[2] = 0
        ElseIf $OverFlag[3] Then
            ConsoleWrite(' Focus-Loss: Label4' & @CR)
            GUICtrlSetBkColor($MenuItems[3], $GUI_MENU_COLOR)
            $OverFlag[3] = 0
        EndIf
     EndIf
    ;#=======================================#
    ;# Check if an element has been clicked  #
    ;#=======================================#
    $nMsg = GUIGetMsg()
    Switch $nMsg
         Case $GUI_EVENT_PRIMARYDOWN
             _SendMessage($GUI_WHNDL, $WM_SYSCOMMAND, 0xF012, 0)    ;#(0xF012 = MAKES GUI DRAGGABLE)
         Case $GUI_EVENT_CLOSE, $GUI_CLOSEBTN
            _MTSkin_GUIDelete($GUI_WHNDL)
            Exit
         Case $GUI_EVENT_MINIMIZE, $GUI_MINIMIZEBTN
            GUISetState(@SW_MINIMIZE)
         Case $MenuItems[0]
            MsgBox(0, "GUI Event","Menu item 1 clicked")
            _Switch_MenuItem(0)
         Case $MenuItems[1]
            MsgBox(0, "GUI Event","Menu item 2 clicked")
            _Switch_MenuItem(1)
         Case $MenuItems[2]
            MsgBox(0, "GUI Event","Menu item 3 clicked")
            _Switch_MenuItem(2)
            _HighlightSeletedItem($MenuItems, 2)
         Case $MenuItems[3]
            MsgBox(0, "GUI Event","Menu item 4 clicked")
            _Switch_MenuItem(3)
            _HighlightSeletedItem($MenuItems, 3)
    EndSwitch
 WEnd


#Region "FUNCTIONS DEFINITION" ----------------------------------------------------------------


Func _InitContentOnStart()
   ;#Here I choose to initialize content (on start of the program) with the 1st menu item (value 0)
   _CreateMenu1Content()
   _HighlightSeletedItem($MenuItems, 0)
   $MENU_CURR_INDEX=0       ;Set the current index value to 0
EndFunc


Func _HighlightSeletedItem($handles, $selected)
      For $i=0 To Ubound($handles)-1
         GUICtrlSetFont($handles[$i], 10, 400, 0, "Segoe UI")
      Next
      GUICtrlSetFont($handles[$selected], 10, 800, 0, "Segoe UI")
EndFunc



Func _Switch_MenuItem($selected)

      $MENU_PREV_INDEX=$MENU_CURR_INDEX ;First set the previous index value
      $MENU_CURR_INDEX=$selected        ;Then set the new current index value
      ;#[1]=> Delete Previous Content
         Switch $MENU_PREV_INDEX
            Case "0"
               ;;0 => MenuItem1
               _DeleteMenu1Content()
            Case "1"
               ;;1 => MenuItem2
               _DeleteMenu2Content()
            Case "2"
               ;;2 => MenuItem3
               _DeleteMenu3Content()
            Case "3"
               ;;3 => MenuItem4
               _DeleteMenu4Content()
            EndSwitch

      ;#[2]=> Display New Content
         Switch $MENU_CURR_INDEX
            Case "0"
               _HighlightSeletedItem($MenuItems, 0)
               _CreateMenu1Content()
            Case "1"
               _HighlightSeletedItem($MenuItems, 1)
               _CreateMenu2Content()
            Case "2"
               _HighlightSeletedItem($MenuItems, 2)
               _CreateMenu3Content()
            Case "3"
               _HighlightSeletedItem($MenuItems, 3)
               _CreateMenu4Content()
         EndSwitch

EndFunc ;=> _Switch_MenuItem()

Func _CreateMenu1Content()
     $ScanState = GUICtrlCreateLabel("Specify the location to save the backup (type, browse, or drag path)", $GUI_MENUBKG_WIDTH+15, 40, 430, 23)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
     $SavePath = GUICtrlCreateInput("", $GUI_MENUBKG_WIDTH+15, 60, 430, 23)
        GUICtrlSetState($SavePath, $GUI_DROPACCEPTED)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
     $BrowseSavePath = GUICtrlCreateButton("...", $GUI_MENUBKG_WIDTH+450, 60, 20, 23)
     $UI = GUICtrlCreateLabel("Enter the Username (SSO) you want to backup.", $GUI_MENUBKG_WIDTH+15, 90, 250, 23)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
     $Name = GUICtrlCreateInput("", $GUI_MENUBKG_WIDTH+15, 110, 80, 23)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
     $MultipleUser = GUICtrlCreateCheckbox("All users logged in within the last 21 days",  $GUI_MENUBKG_WIDTH+100, 110, 400, 23)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
     $Cancel = GUICtrlCreateButton("Cancel", $GUI_MENUBKG_WIDTH+300, 290, 95, 32)
         GUICtrlSetColor(-1, 0xffffff)
         GUICtrlSetState($Cancel, $GUI_HIDE)
     $ShowTime = GUICtrlCreateLabel("", $GUI_MENUBKG_WIDTH+120, 130, 100, 15, $SS_RIGHT)
     $ShowSize = GUICtrlCreateLabel("", $GUI_MENUBKG_WIDTH+140, 150, 100, 15, $SS_RIGHT)
     $ProgressBar = GUICtrlCreateProgress($GUI_MENUBKG_WIDTH+180, 180, 370, 20)
        GUICtrlSetState($ProgressBar, $GUI_HIDE)
     $ProgressText = GUICtrlCreateLabel("", $GUI_MENUBKG_WIDTH+200, 203, 100, 15, $SS_RIGHT)
     $ShowWaitMessage = GUICtrlCreateLabel("Please  wait, setting up", $GUI_MENUBKG_WIDTH+220, 200, 110, 15)
        GUICtrlSetState($ShowWaitMessage, $GUI_HIDE)
     $ShowWaitMessageDots = GUICtrlCreateLabel($WaitMessageDots, $GUI_MENUBKG_WIDTH+250, 200, 200, 15)
        GUICtrlSetState($ShowWaitMessageDots, $GUI_HIDE)
     $ShowCurrentFile = GUICtrlCreateLabel("", $GUI_MENUBKG_WIDTH+10 , 200, 480, 15, $DT_END_ELLIPSIS)
     $AL = GUICtrlCreateLabel ("Please select the type of backup required.", $GUI_MENUBKG_WIDTH+15, 140, 300, 20)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
     $LogicFiles = GUICtrlCreateCombo ("", $GUI_MENUBKG_WIDTH+15, 165, 200, 200)
        GUICtrlSetData($LogicFiles, "Full Backup|Configuration backup")
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
    Global $Go = GUICtrlCreateButton("Back-Up", $GUI_MENUBKG_WIDTH+400, 290, 95, 32)
         GUICtrlSetColor(-1, 0xffffff)
         GUICtrlSetBkColor(-1, $GUI_FONT_COLOR)
    Local $AccelKeys[1][2] = [["{ENTER}", $Go]]
    GUISetAccelerators($AccelKeys)

    While 1
        GLOBAL $LogicFile = ""
                Switch GUICtrlRead($LogicFile)
            Case "Full Backup"
                $LogicFile = "config_XML\MigUserCustom.xml"
                ExitLoop
            Case "Configuration backup" ; Does not work as of 24/01
                $LogicFile = "config_XML\MigUserCustom_VOD.xml"
                Exitloop
        EndSwitch
    WEnd


        ; Build the Argument Variable
    If $LastState == 1 And GUICtrlRead($MultipleUser) == 4 Then
        GUICtrlSetState($Name, $GUI_Enable)
    EndIf
    If $LastState == 4 And GUICtrlRead($MultipleUser) == 1 Then
        GUICtrlSetState($Name, $GUI_DISABLE)
    EndIf




While 1
                    $MSG = GUIGetMsg()
        Switch $MSG

            Case $Go
                Do
                    $GetName = StringUpper(StringReplace(GUICtrlRead($Name), "", "_"))
                    $GetSavePath = GUICtrlRead($SavePath)
                    If $GetName == "" And GUICtrlRead($MultipleUser) == 4 Then
                        MsgBox(16, "ERROR", "Please enter an SSO to backup OR select the ALL PROFILES option")
                                Else
                                    $Date = _NowCalcDate()
                                    $DateBreak = StringSplit($Date, "/")
                                    $FullSavePath = StringUpper(StringReplace($GetSavePath & "\" & $GetName & $DateBreak[2] & $DateBreak[3] & StringRight($DateBreak[1], 2), "\\", "\"))
                                If StringLeft($FullSavePath, 1) == "\" Then $FullSavePath = "\" & $FullSavePath
                                    $Exist = FileExists($FullSavePath)
                                Local $YesOrNo
                                If $Exist Then $YesOrNo = MsgBox(4, "Overwrite?", "The save path specified already exists:" & @CR & $FullSavePath & @CR & @CR & "Overwrite?")
                                If $YesOrNo == 6 Or Not $Exist Then
                                        $TempFile = _TempFile($FullSavePath)
                                        $TestTempFile = FileOpen($TempFile, 1 + 8)
                                        FileClose($TestTempFile)
                                        FileDelete($TempFile)
                                If $TestTempFile == -1 Then
                                        MsgBox(16, "ERROR", "The path you have specified does not exist or is not writable.  Please check the path.")
                                Else
                                        $StartTime = TimerInit()
                                        GUICtrlDelete($Go)
                                        GUICtrlSetState($Cancel, $GUI_SHOW)
                                        GUICtrlSetState($SavePath, $GUI_DISABLE)
                                        GUICtrlSetState($BrowseSavePath, $GUI_DISABLE)
                                        GUICtrlSetState($Name, $GUI_DISABLE)
                                        _BuildUSMTCommand($FullSavePath, $GetName)
                                    EndIf
                                EndIf
                            EndIf
                    Until True = False
            Case $BrowseSavePath
                $Where = FileSelectFolder("Choose the location to save the data", "", 1 + 4)
                GUICtrlSetData($SavePath, $Where)
        EndSwitch
    WEnd

EndFunc

Interestingly, the GUI launches when the While loop is set to 0, but when set to 1 it hangs so the loop must be getting stuck and not exiting somewhere.

any more suggestions would be greatly appreciated.

Thanks

USMT5GUI_Final2.au3

Link to comment
Share on other sites

The biggest problem now that I see is that you have 2 While Loop involving $MSG = GUIGetMsg().  In an AutoIt GUI that is not possible, you need to gather all the logic into a single loop.

Link to comment
Share on other sites

7 minutes ago, Nine said:

The biggest problem now that I see is that you have 2 While Loop involving $MSG = GUIGetMsg().  In an AutoIt GUI that is not possible, you need to gather all the logic into a single loop.

Morning Nine,

I did initially think the same,  the original $nMsg Variable I renamed to $MSG to test. Is this also not possible? Originally I did the test with a completely random variable name, i.e $TES.

But GUI fails to launch when the while loop is set to 1 and when on 0 the GUI launches and everything works apart from, of course, the Backup Button.

Would you have any suggestions on how I could clean this up? My writing style has never been the cleanest.

 

Link to comment
Share on other sites

If this is of anyhelp the original GUI and code looked like this;

 

GUISetState()
; Create a GUI
$Main = GUICreate("USMT5 Front End - NBCUniversal " & Chr(169) & "  2020", 500, 335, -1, -1, Default, $WS_EX_ACCEPTFILES)
GUISetBkColor(0xb2ccff, $Main)
GUISetFont(8.5, 400)
GUICtrlCreateLabel("Specify the location to save the backup (type, browse, or drag path)", 10, 10, 480, 15)
$SavePath = GUICtrlCreateInput("", 10, 30, 445, 20)
GUICtrlSetState($SavePath, $GUI_DROPACCEPTED)
$BrowseSavePath = GUICtrlCreateButton("...", 460, 30, 30, 20)
GUICtrlCreateLabel("Enter the Username (SSO) you want to backup.", 10, 60, 230, 15)
$Name = GUICtrlCreateInput("", 10, 80, 80, 20)
GUICtrlSetState($Name, $GUI_SHOW)
$MultipleUser = GUICtrlCreateCheckbox("Backup all users that have logged in within 21 days", 100, 80, 480, 20)
;GUICtrlCreateLabel("Repair Number", 220, 80, 130, 15)
;$Number = GUICtrlCreateInput("", 220, 100, 130, 20)
;GUICtrlCreateLabel("Tech's Initials", 360, 80, 130, 15)
;$Tech = GUICtrlCreateInput("", 360, 100, 130, 20)
$Go = GUICtrlCreateButton("Backup", 435, 130, 60, 25)
GUICtrlSetFont($Go, 10, 400)
$Cancel = GUICtrlCreateButton("Cancel", 385, 130, 60, 25)
GUICtrlSetState($Cancel, $GUI_HIDE)
GUICtrlSetFont($Cancel, 10, 400)
; Progress Bar Needs Work!
$ShowTime = GUICtrlCreateLabel("", 390, 130, 100, 15, $SS_RIGHT)
$ShowSize = GUICtrlCreateLabel("", 390, 150, 100, 15, $SS_RIGHT)
$ProgressBar = GUICtrlCreateProgress(10, 180, 370, 20)
GUICtrlSetState($ProgressBar, $GUI_HIDE)
$ProgressText = GUICtrlCreateLabel("", 390, 203, 100, 15, $SS_RIGHT)
$ShowWaitMessage = GUICtrlCreateLabel("Please  wait, setting up", 174, 200, 110, 15)
GUICtrlSetState($ShowWaitMessage, $GUI_HIDE)
$ShowWaitMessageDots = GUICtrlCreateLabel($WaitMessageDots, 284, 200, 200, 15)
GUICtrlSetState($ShowWaitMessageDots, $GUI_HIDE)
$ShowCurrentFile = GUICtrlCreateLabel("", 50 , 200, 480, 15, $DT_END_ELLIPSIS)
GUISetState(@SW_SHOW, $Main)


GUICtrlCreateLabel ("Please select the type of backup required.", 10, 110, 300, 20)
$LogicFiles = GUICtrlCreateCombo ("", 10, 130, 200, 200)
   GUICtrlSetData($LogicFiles, "Full Backup|Configuration backup")
     GUISetState(@SW_SHOW)


    While 1
        Local $LogicFile = ""
                Switch GUICtrlRead($LogicFile)
            Case "Full Backup"
                $LogicFile = "config_XML\MigUserCustom.xml"
                ExitLoop
            Case "Configuration backup" ; Does not work as of 24/01
                $LogicFile = "config_XML\MigUserCustom_VOD.xml"
                Exitloop
            EndSwitch
    WEnd
Do
    If $MSG == $GUI_EVENT_CLOSE Then Exit
    If $MSG == $GUI_EVENT_CLOSE Then Exit

    If $MSG == $BrowseSavePath Then
        $Where = FileSelectFolder("Choose the location to save the data", "", 1 + 4)
        GUICtrlSetData($SavePath, $Where)
    EndIf


    If $MSG == $Go Then
        $GetName = StringUpper(StringReplace(GUICtrlRead($Name), " ", "_"))
        $GetSavePath = GUICtrlRead($SavePath)
        If $GetName == "" And GUICtrlRead($MultipleUser) == 4 Then
            MsgBox(16, "ERROR", "Please enter an SSO to backup OR select the ALL PROFILES option")

                            Else
                                $Date = _NowCalcDate()
                                $DateBreak = StringSplit($Date, "/")
                                $FullSavePath = StringUpper(StringReplace($GetSavePath & "\" & $GetName & $DateBreak[2] & $DateBreak[3] & StringRight($DateBreak[1], 2), "\\", "\"))
                                If StringLeft($FullSavePath, 1) == "\" Then $FullSavePath = "\" & $FullSavePath
                                $Exist = FileExists($FullSavePath)
                                Local $YesOrNo
                                If $Exist Then $YesOrNo = MsgBox(4, "Overwrite?", "The save path specified already exists:" & @CR & $FullSavePath & @CR & @CR & "Overwrite?")
                                If $YesOrNo == 6 Or Not $Exist Then
                                    $TempFile = _TempFile($FullSavePath)
                                    $TestTempFile = FileOpen($TempFile, 1 + 8)
                                    FileClose($TestTempFile)
                                    FileDelete($TempFile)
                                    If $TestTempFile == -1 Then
                                        MsgBox(16, "ERROR", "The path you have specified does not exist or is not writable.  Please check the path.")
                                    Else
                                        $StartTime = TimerInit()
                                        GUICtrlDelete($Go)
                                        GUICtrlSetState($Cancel, $GUI_SHOW)
                                        GUICtrlSetState($SavePath, $GUI_DISABLE)
                                        GUICtrlSetState($BrowseSavePath, $GUI_DISABLE)
                                        GUICtrlSetState($Name, $GUI_DISABLE)
                                        _BuildUSMTCommand($FullSavePath, $GetName, $aUG)

                        EndIf
                    EndIf
                EndIf

            EndIf

    Until True == False

This has been working, but the whole piece of code was not inside of a function.

Link to comment
Share on other sites

The problem is not the name of the variable.  The problem is the simple existence of 2 while loops.  You can not have 2 embedded while loops in an AutoIt GUI.  You need to bring your second while loop contained in the function  _CreateMenu1Content() somehow in the first while loop at the beginning of the script.

Link to comment
Share on other sites

12 minutes ago, Nine said:

The problem is not the name of the variable.  The problem is the simple existence of 2 while loops.  You can not have 2 embedded while loops in an AutoIt GUI.  You need to bring your second while loop contained in the function  _CreateMenu1Content() somehow in the first while loop at the beginning of the script.

Progress!! I moved the Do section into a case within the first loop, removed the Do...Until and the buttons are working flawlessly. That is until I change to "LoadState" and back which seems to be failing to load the buttons functionality. I shall troubleshoot that now as I'm sure it shouldn't be too hard.

As they say here, Your an absolute G fam... haha honestly been a big help. The new code (although I literally cut and pasted) looks like;

While 1

    $tPoint = _WinAPI_GetMousePos()
    ;#==========================================#
    ;# Check if the cursor is over a menu item  #
    ;#==========================================#
    If _WinAPI_WindowFromPoint($tPoint) = $hOvrLblWnd[0] Then
        If Not $OverFlag[0] Then
            ConsoleWrite(' Over-Detection: Label1' & @CR)
            GUICtrlSetBkColor($MenuItems[0], $GUI_MENU_HOVER_COLOR)
            $OverFlag[0] = 1
        EndIf
    ElseIf _WinAPI_WindowFromPoint($tPoint) = $hOvrLblWnd[1] Then
        If Not $OverFlag[1] Then
            ConsoleWrite(' Over-Detection: Label2' & @CR)
            GUICtrlSetBkColor($MenuItems[1], $GUI_MENU_HOVER_COLOR)
            $OverFlag[1] = 1
        EndIf
    ElseIf _WinAPI_WindowFromPoint($tPoint) = $hOvrLblWnd[2] Then
        If Not $OverFlag[2] Then
            ConsoleWrite(' Over-Detection: Label3' & @CR)
            GUICtrlSetBkColor($MenuItems[2], $GUI_MENU_HOVER_COLOR)
            $OverFlag[2] = 1
        EndIf
    ElseIf _WinAPI_WindowFromPoint($tPoint) = $hOvrLblWnd[3] Then
        If Not $OverFlag[3] Then
            ConsoleWrite(' Over-Detection: Label4' & @CR)
            GUICtrlSetBkColor($MenuItems[3], $GUI_MENU_HOVER_COLOR)
            $OverFlag[3] = 1
        EndIf
    Else
       ;#========================================#
       ;# Check if focus is lost on a menu item  #
       ;#========================================#
        If $OverFlag[0] Then
            ConsoleWrite(' Focus-Loss: Label1' & @CR)
            GUICtrlSetBkColor($MenuItems[0], $GUI_MENU_COLOR)
            $OverFlag[0] = 0
        ElseIf $OverFlag[1] Then
            ConsoleWrite(' Focus-Loss: Label2' & @CR)
            GUICtrlSetBkColor($MenuItems[1], $GUI_MENU_COLOR)
            $OverFlag[1] = 0
        ElseIf $OverFlag[2] Then
            ConsoleWrite(' Focus-Loss: Label3' & @CR)
            GUICtrlSetBkColor($MenuItems[2], $GUI_MENU_COLOR)
            $OverFlag[2] = 0
        ElseIf $OverFlag[3] Then
            ConsoleWrite(' Focus-Loss: Label4' & @CR)
            GUICtrlSetBkColor($MenuItems[3], $GUI_MENU_COLOR)
            $OverFlag[3] = 0
        EndIf
     EndIf
    ;#=======================================#
    ;# Check if an element has been clicked  #
    ;#=======================================#
    $nMsg = GUIGetMsg()
    Switch $nMsg
         Case $GUI_EVENT_PRIMARYDOWN
             _SendMessage($GUI_WHNDL, $WM_SYSCOMMAND, 0xF012, 0)    ;#(0xF012 = MAKES GUI DRAGGABLE)
         Case $GUI_EVENT_CLOSE, $GUI_CLOSEBTN
            _MTSkin_GUIDelete($GUI_WHNDL)
            Exit
         Case $GUI_EVENT_MINIMIZE, $GUI_MINIMIZEBTN
            GUISetState(@SW_MINIMIZE)
         Case $MenuItems[0]
            MsgBox(0, "GUI Event","Menu item 1 clicked")
            _Switch_MenuItem(0)
         Case $MenuItems[1]
            MsgBox(0, "GUI Event","Menu item 2 clicked")
            _Switch_MenuItem(1)
         Case $MenuItems[2]
            MsgBox(0, "GUI Event","Menu item 3 clicked")
            _Switch_MenuItem(2)
            _HighlightSeletedItem($MenuItems, 2)
         Case $MenuItems[3]
            MsgBox(0, "GUI Event","Menu item 4 clicked")
            _Switch_MenuItem(3)
            _HighlightSeletedItem($MenuItems, 3)
         Case $Go
                    $GetName = StringUpper(StringReplace(GUICtrlRead($Name), "", "_"))
                    $GetSavePath = GUICtrlRead($SavePath)
                    If $GetName == "" And GUICtrlRead($MultipleUser) == 4 Then
                        MsgBox(16, "ERROR", "Please enter an SSO to backup OR select the ALL PROFILES option")
                                Else
                                    $Date = _NowCalcDate()
                                    $DateBreak = StringSplit($Date, "/")
                                    $FullSavePath = StringUpper(StringReplace($GetSavePath & "\" & $GetName & $DateBreak[2] & $DateBreak[3] & StringRight($DateBreak[1], 2), "\\", "\"))
                                If StringLeft($FullSavePath, 1) == "\" Then $FullSavePath = "\" & $FullSavePath
                                    $Exist = FileExists($FullSavePath)
                                Local $YesOrNo
                                If $Exist Then $YesOrNo = MsgBox(4, "Overwrite?", "The save path specified already exists:" & @CR & $FullSavePath & @CR & @CR & "Overwrite?")
                                If $YesOrNo == 6 Or Not $Exist Then
                                        $TempFile = _TempFile($FullSavePath)
                                        $TestTempFile = FileOpen($TempFile, 1 + 8)
                                        FileClose($TestTempFile)
                                        FileDelete($TempFile)
                                If $TestTempFile == -1 Then
                                        MsgBox(16, "ERROR", "The path you have specified does not exist or is not writable.  Please check the path.")
                                Else
                                        $StartTime = TimerInit()
                                        GUICtrlDelete($Go)
                                        GUICtrlSetState($Cancel, $GUI_SHOW)
                                        GUICtrlSetState($SavePath, $GUI_DISABLE)
                                        GUICtrlSetState($BrowseSavePath, $GUI_DISABLE)
                                        GUICtrlSetState($Name, $GUI_DISABLE)
                                        _CreateMenu1Content()
                                        _BuildUSMTCommand($FullSavePath, $GetName)
                                    EndIf
                                EndIf
                            EndIf
            Case $BrowseSavePath
                $Where = FileSelectFolder("Choose the location to save the data", "", 1 + 4)
                GUICtrlSetData($SavePath, $Where)
    EndSwitch
 WEnd


#Region "FUNCTIONS DEFINITION" ----------------------------------------------------------------


Func _InitContentOnStart()
   ;#Here I choose to initialize content (on start of the program) with the 1st menu item (value 0)
   _CreateMenu1Content()
   _HighlightSeletedItem($MenuItems, 0)
   $MENU_CURR_INDEX=0       ;Set the current index value to 0
EndFunc


Func _HighlightSeletedItem($handles, $selected)
      For $i=0 To Ubound($handles)-1
         GUICtrlSetFont($handles[$i], 10, 400, 0, "Segoe UI")
      Next
      GUICtrlSetFont($handles[$selected], 10, 800, 0, "Segoe UI")
EndFunc



Func _Switch_MenuItem($selected)

      $MENU_PREV_INDEX=$MENU_CURR_INDEX ;First set the previous index value
      $MENU_CURR_INDEX=$selected        ;Then set the new current index value
      ;#[1]=> Delete Previous Content
         Switch $MENU_PREV_INDEX
            Case "0"
               ;;0 => MenuItem1
               _DeleteMenu1Content()
            Case "1"
               ;;1 => MenuItem2
               _DeleteMenu2Content()
            Case "2"
               ;;2 => MenuItem3
               _DeleteMenu3Content()
            Case "3"
               ;;3 => MenuItem4
               _DeleteMenu4Content()
            EndSwitch

      ;#[2]=> Display New Content
         Switch $MENU_CURR_INDEX
            Case "0"
               _HighlightSeletedItem($MenuItems, 0)
               _CreateMenu1Content()
            Case "1"
               _HighlightSeletedItem($MenuItems, 1)
               _CreateMenu2Content()
            Case "2"
               _HighlightSeletedItem($MenuItems, 2)
               _CreateMenu3Content()
            Case "3"
               _HighlightSeletedItem($MenuItems, 3)
               _CreateMenu4Content()
         EndSwitch

EndFunc ;=> _Switch_MenuItem()

Func _CreateMenu1Content()
     $ScanState = GUICtrlCreateLabel("Specify the location to save the backup (type, browse, or drag path)", $GUI_MENUBKG_WIDTH+15, 40, 430, 23)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
     $SavePath = GUICtrlCreateInput("", $GUI_MENUBKG_WIDTH+15, 60, 430, 23)
        GUICtrlSetState($SavePath, $GUI_DROPACCEPTED)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
     $BrowseSavePath = GUICtrlCreateButton("...", $GUI_MENUBKG_WIDTH+450, 60, 20, 23)
     $UI = GUICtrlCreateLabel("Enter the Username (SSO) you want to backup.", $GUI_MENUBKG_WIDTH+15, 90, 250, 23)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
     $Name = GUICtrlCreateInput("", $GUI_MENUBKG_WIDTH+15, 110, 80, 23)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
     $MultipleUser = GUICtrlCreateCheckbox("All users logged in within the last 21 days",  $GUI_MENUBKG_WIDTH+100, 110, 400, 23)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
     $Cancel = GUICtrlCreateButton("Cancel", $GUI_MENUBKG_WIDTH+300, 290, 95, 32)
         GUICtrlSetColor(-1, 0xffffff)
         GUICtrlSetState($Cancel, $GUI_HIDE)
     $ShowTime = GUICtrlCreateLabel("", $GUI_MENUBKG_WIDTH+120, 130, 100, 15, $SS_RIGHT)
     $ShowSize = GUICtrlCreateLabel("", $GUI_MENUBKG_WIDTH+140, 150, 100, 15, $SS_RIGHT)
     $ProgressBar = GUICtrlCreateProgress($GUI_MENUBKG_WIDTH+180, 180, 370, 20)
        GUICtrlSetState($ProgressBar, $GUI_HIDE)
     $ProgressText = GUICtrlCreateLabel("", $GUI_MENUBKG_WIDTH+200, 203, 100, 15, $SS_RIGHT)
     $ShowWaitMessage = GUICtrlCreateLabel("Please  wait, setting up", $GUI_MENUBKG_WIDTH+220, 200, 110, 15)
        GUICtrlSetState($ShowWaitMessage, $GUI_HIDE)
     $ShowWaitMessageDots = GUICtrlCreateLabel($WaitMessageDots, $GUI_MENUBKG_WIDTH+250, 200, 200, 15)
        GUICtrlSetState($ShowWaitMessageDots, $GUI_HIDE)
     $ShowCurrentFile = GUICtrlCreateLabel("", $GUI_MENUBKG_WIDTH+10 , 200, 480, 15, $DT_END_ELLIPSIS)
     $AL = GUICtrlCreateLabel ("Please select the type of backup required.", $GUI_MENUBKG_WIDTH+15, 140, 300, 20)
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
     $LogicFiles = GUICtrlCreateCombo ("", $GUI_MENUBKG_WIDTH+15, 165, 200, 200)
        GUICtrlSetData($LogicFiles, "Full Backup|Configuration backup")
        GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
        GUICtrlSetColor(-1, $GUI_TITLES_COLOR)
     $Go = GUICtrlCreateButton("Back-Up", $GUI_MENUBKG_WIDTH+400, 290, 95, 32)
         GUICtrlSetColor(-1, 0xffffff)
         GUICtrlSetBkColor(-1, $GUI_FONT_COLOR)
    Local $AccelKeys[1][2] = [["{ENTER}", $Go]]
    GUISetAccelerators($AccelKeys)

    While 1
        GLOBAL $LogicFile = ""
                Switch GUICtrlRead($LogicFile)
            Case "Full Backup"
                $LogicFile = "config_XML\MigUserCustom.xml"
                ExitLoop
            Case "Configuration backup" ; Does not work as of 24/01
                $LogicFile = "config_XML\MigUserCustom_VOD.xml"
                Exitloop
        EndSwitch
    WEnd


        ; Build the Argument Variable
    If $LastState == 1 And GUICtrlRead($MultipleUser) == 4 Then
        GUICtrlSetState($Name, $GUI_Enable)
    EndIf
    If $LastState == 4 And GUICtrlRead($MultipleUser) == 1 Then
        GUICtrlSetState($Name, $GUI_DISABLE)
    EndIf



EndFunc

 

Link to comment
Share on other sites

Link to comment
Share on other sites

1 hour ago, Nine said:

Yep, looks better, although I didn't run it. In Scite do a Ctrl-t (tidy) to format the code, it will look even better.  And remove those ugly == comparaisons ;)

Good luck !

Really appreciate the help. Will post back up with the finished product incase anyone else needs help

Thanks again!

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...