Tn60 Posted April 29, 2020 Posted April 29, 2020 Hi, I wrote a program to search for and display the path of a folder or file, but when I select a file or folder in the dialog box, the window closes, and the path is not displayed in the text box. Thanks in advance for the help. TN Form2_inp.au3
FrancescoDiMuro Posted April 29, 2020 Posted April 29, 2020 @Tn60 Could you please post the code with the <> code tag instead of attach it? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
faustf Posted April 29, 2020 Posted April 29, 2020 i prefer this style for script sorry try to start at base expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GuiOnEventMode", 1) Opt("GUICloseOnESC", 0) Global $txt_folder = "C:\",$Input20 Global $txt_file,$Radio1,$Radio2 Form2_inp() Func Form2_inp() #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Browse Button", 320, 124, 193, 115) $Input20 = GUICtrlCreateInput("", 21, 19, 281, 21) $Button20 = GUICtrlCreateButton("Browse...", 240, 65, 64, 25, 0) $Button21 = GUICtrlCreateButton("GO", 150, 65, 75, 25, 0) $Group1 = GUICtrlCreateGroup("Browse what", 20, 44, 120, 63) $Radio1 = GUICtrlCreateRadio("Folder", 26, 60, 113, 17) $Radio2 = GUICtrlCreateRadio("File to open", 26, 80, 113, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetState($Radio2, $GUI_CHECKED) GUICtrlSetState($Button20, $GUI_CHECKED) GUISetOnEvent($GUI_EVENT_CLOSE, _Close) GUICtrlSetOnEvent($Button20, _apri_percorso) EndFunc Func _Close() Exit EndFunc Func _apri_percorso() GUICtrlSetData($Input20, "") If GuiCtrlRead($Radio1) = $GUI_CHECKED Then $txt_folder=FileSelectFolder( "Open", "C:\") GUICtrlSetData($Input20,$txt_folder) ;MsgBox(0,0,$txt_folder) GUICtrlSetData($Input20,$txt_folder) ElseIf GuiCtrlRead($Radio2) = $GUI_CHECKED Then $txt_file=FileOpenDialog("Open", "C:\","(*.exe)") GUICtrlSetData($Input20,$txt_file) ;MsgBox(0,0,$txt_file) EndIf EndFunc ; Add strings ; Finish strings While 1 Sleep(100) WEnd
Subz Posted April 29, 2020 Posted April 29, 2020 You appear to mixing Switch with Select try: expandcollapse popup#include <GUIConstantsEx.au3> Global $sFilePath, $sFolderPath _FormInput() Func _FormInput() Local $hGuiForm = GUICreate("Browse Button", 320, 124, 193, 115) Local $idPath = GUICtrlCreateInput("C:\", 21, 19, 281, 21) Local $idBrowse = GUICtrlCreateButton("Browse...", 240, 65, 64, 25, 0) Local $idSelect = GUICtrlCreateButton("GO", 150, 65, 75, 25, 0) GUICtrlCreateGroup("Browse what", 20, 44, 120, 63) Local $idFolder = GUICtrlCreateRadio("Folder", 26, 60, 113, 17) Local $idFile = GUICtrlCreateRadio("File to open", 26, 80, 113, 17) GUICtrlSetState($idFile, $GUI_CHECKED) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($hGuiForm) ExitLoop Case $idSelect GUIDelete($hGuiForm) ExitLoop Case $idBrowse If GuiCtrlRead($idFolder) = $GUI_CHECKED Then $sFolderPath = FileSelectFolder("Open", (FileExists(GUICtrlRead($idPath)) ? GUICtrlRead($idPath) : "C:\")) If @error Then ContinueLoop GUICtrlSetData($idPath,$sFolderPath) ElseIf GuiCtrlRead($idFile) = $GUI_CHECKED Then $sFilePath = FileOpenDialog("Open", (FileExists(GUICtrlRead($idPath)) ? GUICtrlRead($idPath) : "C:\"), "(*.exe)") If @error Then ContinueLoop GUICtrlSetData($idPath,$sFilePath) EndIf EndSwitch WEnd EndFunc
Tn60 Posted April 29, 2020 Author Posted April 29, 2020 Hi Thanks for the help. This is what i wanted! TN
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