Jump to content
byarotsky

Issue with displaying GUICtrlCreateRadio in a GUICtrlSetOnEvent script

Recommended Posts

byarotsky

I am working on a script that pulls the current time from the internet and then reads contents from our backup server based on the month and week folders that are already created. This script will ultimate pass variables to another program that will restore the data from the respective folder to the computer that the script it running on. The script is built to find the 'windows' folders in the server structure which is \\server\serverfolder\01_16\3week

\\server\serverfolder - is the server share

01_16 - is month and year as to sort properly

3week - is obviously the week

Within the week folder there are user folders (eg. bsmith, jdoe, ganderson), in these folders are backups of full hard drives with include the windows folder which we are looking for.The script is running and is fully function the first time that it is run. I have also added a back button so if for some reason you are in the wrong list of folders you can navigate to the correct folder and then show the results again.

The issue I am having is that I can show the contents and everything works well, unless I use the back button and navigate to a different set of folders (different week). The radio buttons do not respond properly. They will show both incorrect data and the count of radio buttons is not being updated.

I have attempted to look for a solution and have tried many different ideas, but I just don't fully understand how a GUICtrlCreateRadio in a for loop with GUICtrlSetOnEvent should work.

 

Any suggestions would be greatly appreciated. I apologize for the messy code.

#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>


; #FUNCTION# ====================================================================================================================
; Name ..........: _GetTimeOnline
; Description ...: Retrieve the current date and time from TimeAPI.org.
; Syntax ........: _GetTimeOnline($iTimeZone)
; Parameters ....: $iTimeZone           - An integer value of the timezone .
;                  0 - UTC (Universal Time)
;                  1 - EST (Eastern Time)
;                  2 - CST (Central Time)
;                  3 - MST (Mountain Time)
;                  4 - PST (Pacific Time)
;                  5 - AKST (Alaska Time)
;                  6 - HAST (Hawaii-Aleutian Time)
; Return values .: Success: Returns the current Date and Time in the format YYYY/MM/DD HH:MM:SS
;                  Failure: Sets @error to non-zero and returns the same format as a successful return but using the system time.
; Author ........: guinness
; Link ..........: According to http://www.programmableweb.com/api/timeapi, this is for non-commercial use.
; Example .......: Yes
; ===============================================================================================================================

Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)


Global $vGUI_V = 450
Global $vGUI_ = 400
Local $ServerPath = "\\vault\backups\"
Local $aFileList, $Current_Radio, $CurrentMonthFolder
Local $Current_Gui = GUICreate("Test", 450, 400)
Local $GuiBack = GUICtrlCreateButton("Back", 200, 250, 40, 40)
GUICtrlCreateLabel("Please select the Windows folder to use", 20, 20)

GUICtrlSetOnEvent($GuiBack, "BackPressed")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

_GetTimeOnline(2) ;Central time zone
_SelectFolder()

While 1
    Sleep(100)
WEnd

Exit

Func _GetTimeOnline($iTimeZone)
    ; Retrieve the current time from TimeAPI.org.  Ideal if your Windows clock is out of sync.
    Local $aTimeZone[7] = ['utc', 'est', 'cst', 'mst', 'pst', 'akst', 'hast']
    Local $sRead = BinaryToString(InetRead('http://www.timeapi.org/' & $aTimeZone[$iTimeZone] & '/now?format=\Y/\m/\d%20/\H:\M:\S'))
    If @error Then
        SetError(1, 0, @YEAR & '/' & @MON & '/' & @MDAY & '/' & @HOUR & ':' & @MIN & ':' & @SEC)
    EndIf
    Local $aDays = StringSplit($sRead, "/") ; Split the string of days using the delimiter "," and the default flag value.
    ;    For $i = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values.
    ;        MsgBox(4096, "", "$aDays[" & $i & "] - " & $aDays[$i])
    ;    Next
    $CurrentMonthFolder = $ServerPath & $aDays[2] & "_" & StringTrimLeft($aDays[1], 2) & "\" & Ceiling((@MDAY + (7 - @WDAY)) / 7) & "week"
EndFunc   ;==>_GetTimeOnline

Func _SelectFolder()

    Local Const $sMessage = "Select users folder to restore data from:"

    ; Display an open dialog to select a file.
    Local $sFileSelectFolder = FileSelectFolder($sMessage, $CurrentMonthFolder)

    If @error Then
        ; Display the error message.
        ; MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
        Exit
    Else
        ; Display the selected folder.
        ; MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)
        $aFileList = _FileListToArrayRec($sFileSelectFolder, "Windows", 14, -3, $FLTAR_SORT)
        If @error = 1 Then
            MsgBox($MB_SYSTEMMODAL, "", "Path was invalid or Windows folder not found.")
            _SelectFolder()
        EndIf
        If @error = 9 Then
            MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
            _SelectFolder()
        EndIf
    EndIf
    $CurrentMonthFolder = $sFileSelectFolder
    _ShowGui()
EndFunc   ;==>_SelectFolder

Func _ShowGui()
    Local $startline = 20
    If @error Then
        MsgBox(4096, "ERROR", "Error occured, no INI or incorrect Sections")
    Else
        For $i = 1 To $aFileList[0]
            $Current_Radiou = GUICtrlCreateRadio($aFileList[$i], 25, $startline + 20 * $i, 400)
            GUICtrlSetOnEvent(-1, "myEvent") ; This will tell us which radio was clicked
        Next
    EndIf
    GUISetState(@SW_SHOW, $Current_Gui)
EndFunc   ;==>_ShowGui

Func BackPressed()
;    MsgBox($MB_SYSTEMMODAL, "Go Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
    GUISetState(@SW_HIDE, $Current_Gui)
    _SelectFolder()
EndFunc   ;==>BackPressed

Func myEvent()
    For $x = 1 To $aFileList[0] + 6 ; this is broken
        If GUICtrlRead($x) = 1 Then MsgBox(0, GUICtrlRead($x), GUICtrlRead($x, 1)) ;this is the path to the profile
    Next
EndFunc   ;==>myEvent

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
;           MsgBox($MB_SYSTEMMODAL, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
            Exit
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
;           MsgBox($MB_SYSTEMMODAL, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
        Case @GUI_CtrlId = $GUI_EVENT_RESTORE
;           MsgBox($MB_SYSTEMMODAL, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
    EndSelect
EndFunc   ;==>SpecialEvents

 

Share this post


Link to post
Share on other sites
AutoBert

In OnEventMode you can use @GuiCtrlID to identify the Control which fired the event. So you can use:

MsgBox(0, GUICtrlRead(@GUI_CtrlId), GUICtrlRead(@GUI_CtrlId, 1)) in your func myEvent.

The ControlId you read with $aFileList[0] + 6 maybe wrong when the func ShowGui is executed more then once.

You must also delete the current radios before creating the new radios.

So it's a good idea to store the ControlId's in an array.

Here the complete script:

dynamicRadios.au3

dynamicRadios.au3

Edited by AutoBert

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

  • Similar Content

    • Skeletor
      By Skeletor
      Hi Virtual People,
      My array works perfectly fine. However, what is the best practice if the line in the array doesn't have the correct amount of columns and if I can add a placeholder?

       
      For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") Next  
    • Mannyfresh31
      By Mannyfresh31
      Hello everybody I need help with Opt("GUIOnEventMode",1) 
      I Normally use GUIGetMsg() but I want to learn how GUIOnEventMode works so I created a little test GUI the start button works fine and everything but the problem is that the stop button won't work down below is the code  I made and I'm wondering if someone with experience can explain me and the rest o newbies how it works and also if can post the code already fixed
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> $Stop = False $X=1 $i = 0 Opt("GUIOnEventMode",1) #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 579, 212, 192, 124) Global $Button1 = GUICtrlCreateButton("Stop", 432, 136, 75, 25) Global $Button2 = GUICtrlCreateButton("Start", 96, 136, 75, 25) Global $Progress1 = GUICtrlCreateProgress(24, 40, 526, 49) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUISetOnEvent ($GUI_EVENT_CLOSE, "_exit",$Form1 ) GUICtrlSetOnEvent($Button1,"_Stop") GUICtrlSetOnEvent($Button2,"DecreaseAndIncrement") While 1 sleep(500) WEnd Func _Stop () $Stop = True EndFunc Func _exit () Exit EndFunc Func DecreaseAndIncrement () $Stop = False While $Stop = False $i+=$X ;ConsoleWrite($i & @CRLF) GUICtrlSetData($Progress1,$i) Sleep(80) if $i = 105 Then $X = -1 if $i = 0 Then $X = 1 WEnd EndFunc  
       
      here is the version that works with GUIGetMsg()
       
       
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> $Stop = False $X=1 $i = 0 #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 579, 212, 192, 124) Global $Button1 = GUICtrlCreateButton("Stop", 432, 136, 75, 25) Global $Button2 = GUICtrlCreateButton("Start", 96, 136, 75, 25) Global $Progress1 = GUICtrlCreateProgress(24, 40, 526, 49) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 DecreaseAndIncrement () case $Button1 $Stop = True EndSwitch WEnd Func DecreaseAndIncrement () $Stop = False While $Stop = False $i+=$X ;ConsoleWrite($i & @CRLF) GUICtrlSetData($Progress1,$i) Sleep(80) if $i = 105 Then $X = -1 if $i = 0 Then $X = 1 $nMsg2 = GUIGetMsg() Switch $nMsg2 Case $GUI_EVENT_CLOSE Exit case $Button1 $Stop = True EndSwitch WEnd EndFunc  
       
       
       
       
       
       
    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
    • Skeletor
      By Skeletor
      Hi All,

      I would like to know how you would take a FileLineRead and insert it into an array which then inserts it into Excel?
      One thing to know is the files content is broken up, so I only use half of the content within $FileRead1.
      So its imperative that the $value1, $value2, etc variables be used. 
      Code below:
      $FileRead1 = FileReadLine("C:\temp\sample.txt",1) For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value4, "D1") Next  
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to write a script that moves copies excel cells into an array. I'll than manipulate the values and send array into another program. 
      I don't want range to be specific to a workbook, or sheet, or set of cells.
      I want user to be able to highlight desired cells and to copy either normally ("Ctrl+C") or by a hotkey ("Alt+C"). 
      Could someone help me with this?
      Thank you,
      I've tried to write the framework: (edited)
      #include <MsgBoxConstants.au3> #include <Array.au3> #include <Excel.au3> HotKeySet("!v", "Pastedata") While True Sleep(1000) WEnd func Makearray() local $bArray ;User has cells already copied ;Convert clipboard into an array ;I don;t know how excel stores data to clipboard so don;t know how to bring it into array _Arraydisplay($bArray) MsgBox(0,0,$bArray) return $bArray endfunc func Pastedata() Local $aArray MsgBox(0,0,"wait",1) ;make array based on assumption user has already copied a range to clipboard $aArray = Makearray() ;paste code ;don;t worry about this I got the rest endfunc  
×