Trinnon Posted November 5 Share Posted November 5 I have been working on my application and noticed that the Radio Buttons I use to create files do not function as I would expect. I have them creating a file when selected and then if another Radio Buttons is selected it will delete the original file and create the new file for that selection. What I have noticed is that I can see it create the file from the first Radio Button but if the second Radio Button is selected it does not delete the file until the application is closed. This would be fine except the second Radio Button (Option2) has additional requirements to select one option that starts with the word Pick. Is there a way to make it delete the files when selecting a different option? I run into the same issue when clearing the list boxes. It will keep adding more files and only delete them when the application is closed. In the end if someone selects Option2 I would like them to be forced to pick only one options from that starts with PickOne*. Along with FileFindFirstFile I was trying to use FileFindNextFile to determine if one was selected that start with PickOne. I removed some of this code to work on the other issue. With the files not deleting until after the application closes it is causing issues. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <StaticConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <GUIListBox.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form=\\bjcsccmfr01\osd.files\_prodtsfiles\osdfrontend-v2\optionlistformtest.kxf $Form1_1 = GUICreate("OptionListForm", 627, 437, 324, 124) $List1 = GUICtrlCreateList("", 48, 120, 217, 266,BitOr($GUI_SS_DEFAULT_LIST, $LBS_MULTIPLESEL)) $List2 = GUICtrlCreateList("", 360, 120, 217, 266) $Option1rdo = GUICtrlCreateRadio("Option 1", 48, 24, 73, 25) $Option2rdo = GUICtrlCreateRadio("Option 2", 48, 56, 73, 25) $add = GUICtrlCreateButton("Add", 280, 168, 65, 33) $clear = GUICtrlCreateButton("Clear", 280, 216, 65, 33) $continue = GUICtrlCreateButton("Continue", 265, 390, 100, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GLOBAL $sOptionList1 = @ScriptDir & "\OptionList1.txt" GLOBAL $sOptionList2 = @ScriptDir & "\OptionList2.txt" GLOBAL $sOptionNumber = (@ScriptDir & "\OptionNumber\") DirCreate(@ScriptDir & "\OptionNumber") GLOBAL $sOptionsSelected = (@ScriptDir & "\OptionsSelected\") DirCreate(@ScriptDir & "\OptionsSelected") GLOBAL $OptionPicked = "" GLOBAL $PickOne = "" Global $aList Global $sList While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Option1rdo GUICtrlSetData($List1, "") GUICtrlSetData($List2, "") FileDelete($sOptionNumber & "*") FileDelete($sOptionsSelected & "*") _FileReadToArray($sOptionList1, $aList, $FRTA_NOCOUNT) $sList = _ArrayToString($aList, "|") GUICtrlSetData($List1, $sList, "") FileOpen($sOptionNumber & "Option1", 1) FileClose($sOptionNumber & "Option1") Case $Option2rdo GUICtrlSetData($List1, "") GUICtrlSetData($List2, "") FileDelete($sOptionNumber & "*") FileDelete($sOptionsSelected & "*") _FileReadToArray($sOptionList2, $aList, $FRTA_NOCOUNT) $sList = _ArrayToString($aList, "|") GUICtrlSetData($List1, $sList, "") FileOpen($sOptionNumber & "Option2", 1) FileClose($sOptionNumber & "Option2") Case $add _AddList() Case $clear GUICtrlSetData($List2, "", "") Case $continue _OptionPickTest() If $OptionPicked <> "True" Then MsgBox(0,"Step 1: Error", "Step 1: Pick an Option") Else _PickOneOption2Test() If $PickOne = "False" Then MsgBox(0,"PickOne Verification", $PickOne) Else Exit EndIf EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _AddList() Local $aList = _GUICtrlListBox_GetSelItemsText($List1) Local $sList = _ArrayToString($aList, "|", 1, -1) GUICtrlSetData($List2, $sList, "") If IsArray($aList) Then For $i = 1 to $aList[0] MsgBox($MB_SYSTEMMODAL, "Array Info", "Array Text: " & $aList[$i],1) FileOpen($sOptionsSelected & "\" & $aList[$i],1) FileClose($sOptionsSelected & "\" & $aList[$i]) Next EndIf EndFunc Func _OptionPickTest() If FileExists($sOptionNumber & "Option1") Then Msgbox (0,"Option1 Picked","Option1 Picked") $OptionPicked = "True" EndIf If FileExists($sOptionNumber & "Option2") Then Msgbox (0,"Option2 Picked","Option2 Picked") $OptionPicked = "True" EndIf EndFunc Func _PickOneOption2Test() If FileExists($sOptionNumber & "Option2") Then Msgbox (0,"Option2","Option2 Selected") Else Exit EndIf Local $hSearch = FileFindFirstFile($sOptionsSelected & "Pick*") ; Check if the search was successful, if not display a message and return False. If $hSearch = -1 Then MsgBox($MB_SYSTEMMODAL, "", "Option 2: PICK ONE Main Course.") $PickOne = "False" Return False EndIf FileClose($hSearch) EndFunc Hopefully my explanation makes sense. Thanks, Trinnon. OptionList2.txt OptionList1.txt Link to comment Share on other sites More sharing options...
argumentum Posted November 5 Share Posted November 5 6 minutes ago, Trinnon said: FileOpen($sOptionNumber & "Option1", 1) FileClose($sOptionNumber & "Option1") ..just looking at it. $handle = FileOpen("name", 1) FileClose($handle) Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Trinnon Posted November 5 Author Share Posted November 5 Wow that made life a lot easier! @argumentum I just need to figure out how to stop them from selecting more than one option now. I tried to get this to bring up a result if there are more than one of the options selected. I thought I could do something with $iResult but it appears that is going to count > 1 even if only one is selected. Right now this code stops them from Continue even if only one entree is selected. I can make it Continue if one or more are selected just not sure how to limit it to one entree. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <StaticConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <GUIListBox.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form=\\bjcsccmfr01\osd.files\_prodtsfiles\osdfrontend-v2\optionlistformtest.kxf $Form1_1 = GUICreate("OptionListForm", 627, 437, 324, 124) $List1 = GUICtrlCreateList("", 48, 120, 217, 266,BitOr($GUI_SS_DEFAULT_LIST, $LBS_MULTIPLESEL)) $List2 = GUICtrlCreateList("", 360, 120, 217, 266) $Option1rdo = GUICtrlCreateRadio("Option 1", 48, 24, 73, 25) $Option2rdo = GUICtrlCreateRadio("Option 2", 48, 56, 73, 25) $add = GUICtrlCreateButton("Add", 280, 168, 65, 33) $clear = GUICtrlCreateButton("Clear", 280, 216, 65, 33) $continue = GUICtrlCreateButton("Continue", 265, 390, 100, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GLOBAL $sOptionList1 = @ScriptDir & "\OptionList1.txt" GLOBAL $sOptionList2 = @ScriptDir & "\OptionList2.txt" GLOBAL $sOptionNumber = (@ScriptDir & "\OptionNumber\") DirCreate(@ScriptDir & "\OptionNumber") GLOBAL $sOptionsSelected = (@ScriptDir & "\OptionsSelected\") DirCreate(@ScriptDir & "\OptionsSelected") GLOBAL $OptionPicked = "" GLOBAL $PickOne = "" GLOBAL $iResultCount = "" Global $aList Global $sList While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Option1rdo GUICtrlSetData($List1, "") GUICtrlSetData($List2, "") FileDelete($sOptionNumber & "*") FileDelete($sOptionsSelected & "*") _FileReadToArray($sOptionList1, $aList, $FRTA_NOCOUNT) $sList = _ArrayToString($aList, "|") GUICtrlSetData($List1, $sList, "") $handle = FileOpen($sOptionNumber & "Option1", 1) FileClose($handle) Case $Option2rdo GUICtrlSetData($List1, "") GUICtrlSetData($List2, "") FileDelete($sOptionNumber & "*") FileDelete($sOptionsSelected & "*") _FileReadToArray($sOptionList2, $aList, $FRTA_NOCOUNT) $sList = _ArrayToString($aList, "|") GUICtrlSetData($List1, $sList, "") $handle = FileOpen($sOptionNumber & "Option2", 1) FileClose($handle) Case $add _AddList() Case $clear GUICtrlSetData($List2, "", "") Case $continue Local $PickOne = "" _OptionPickTest() If $OptionPicked <> "True" Then MsgBox(0,"Step 1: Error", "Step 1: Pick an Option") Else _PickOneOption2Test() If $PickOne = "False" or $iResultCount = "ToMany" Then MsgBox(0,"PickOne Verification", $PickOne) Else Exit EndIf EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _AddList() Local $aList = _GUICtrlListBox_GetSelItemsText($List1) Local $sList = _ArrayToString($aList, "|", 1, -1) GUICtrlSetData($List2, $sList, "") If IsArray($aList) Then For $i = 1 to $aList[0] MsgBox($MB_SYSTEMMODAL, "Array Info", "Array Text: " & $aList[$i],1) $handle = FileOpen($sOptionsSelected & "\" & $aList[$i],1) FileClose($handle) Next EndIf EndFunc Func _OptionPickTest() If FileExists($sOptionNumber & "Option1") Then Msgbox (0,"Option1 Picked","Option1 Picked") $OptionPicked = "True" EndIf If FileExists($sOptionNumber & "Option2") Then Msgbox (0,"Option2 Picked","Option2 Picked") $OptionPicked = "True" EndIf EndFunc Func _PickOneOption2Test() If FileExists($sOptionNumber & "Option2") Then Msgbox (0,"Option2","Option2 Selected") Else Exit EndIf ;Local $hSearch = "" ; Local $PickOne = "" Local $hSearch = FileFindFirstFile($sOptionsSelected & "Pick*") ; Check if the search was successful, if not display a message and return False. If $hSearch = -1 Then MsgBox($MB_SYSTEMMODAL, "", "Option 2: PICK ONE Main Course.") $PickOne = "False" Return False EndIf Local $sFileName = "", $iResult = 0; While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop ; Display the file name. MsgBox(0,"iResult",$iResult) $iResult = MsgBox(($MB_OKCANCEL + $MB_SYSTEMMODAL), "", "File: " & $sFileName) Msgbox (0,"PickOne Result",$PickOne) Msgbox (0,"PickOne Result",$iResult) If $iResult > 0 Then Msgbox (0,"PickOne Result","Pick Only one Entree") $iResultCount = "ToMany" EndIf ExitLoop ; If the user clicks on the cancel/close button. WEnd FileClose($hSearch) EndFunc OptionList1.txt OptionList2.txt Link to comment Share on other sites More sharing options...
argumentum Posted November 5 Share Posted November 5 13 minutes ago, Trinnon said: $handle = FileOpen($sOptionNumber & "Option2", 1) FileClose($handle) You open the file in append mode and, close it. What is the meaning of this ? Again, just looking at it. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Trinnon Posted November 5 Author Share Posted November 5 I just need to create the file and then I have a PowerShell script that picks them up and creates variables for SCCM Task Sequences. I could not find a way for AutoIt to create variables so just leaving some breadcrumbs. Kinda sucks but I want to get rid of my current full PowerShell GUI because it is a pain dealing with manually coding the GUI for multiple resolutions. argumentum 1 Link to comment Share on other sites More sharing options...
argumentum Posted November 5 Share Posted November 5 (edited) 39 minutes ago, Trinnon said: I could not find a way for AutoIt to create variables Example() Func Example() ; Create an environment variable called %MYVAR% and assign it a value. When you assign or retrieve an environment variable you do so minus the percentage signs (%). EnvSet("MYVAR", "This is some text from my variable!") ; Retrieve the environment variable that was just assigned a value previously. Local $sEnvVar = EnvGet("MYVAR") ; variable is set for the session Run(@ComSpec & ' /c cls &echo %MYVAR% & pause' & @CRLF) ; Refresh the OS environment for changes to take affect. ;~ EnvUpdate() ; read the help file ; Display the value of the environment variable $MYVAR%. MsgBox(0, "", "The environment variable %MYVAR% has the value of: " & @CRLF & @CRLF & $sEnvVar) EndFunc ;==>Example Edited November 5 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Trinnon Posted November 5 Author Share Posted November 5 Yeh. I gave up on the variables. Some mentioned that AutoIt could not access the COM object for the SCCM Environment. -COMObject Microsoft.SMS.TSEnvironment As long as the front end looks pretty, I will code around what it cannot do. 😊 argumentum 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now