fikri1979 Posted November 28, 2013 Share Posted November 28, 2013 (edited) hello all..... how to create script when I click the "SAVE" button it will be saved in format ".ini " as sample : config.ini ; config2.ini etc and if i click the "LOAD" button, it will look for the file load ".ini" so that it appears in GUI.. if click Save Button will appear and if click Load Button will appear can give me example please? #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 395, 172, 192, 114) $inputhost = GUICtrlCreateInput("Input1", 96, 32, 145, 21) $Label1 = GUICtrlCreateLabel("Host", 32, 32, 26, 17) $inputusername = GUICtrlCreateInput("Input2", 96, 64, 145, 21) $Label2 = GUICtrlCreateLabel("Username", 32, 72, 52, 17) $inputpassword = GUICtrlCreateInput("Input3", 96, 96, 145, 21) $Label3 = GUICtrlCreateLabel("Password", 32, 104, 50, 17) $btnsave = GUICtrlCreateButton("SAVE", 280, 48, 73, 25) $btnload = GUICtrlCreateButton("LOAD", 280, 88, 73, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnsave IniWrite(@ScriptDir & "\Config.ini", "Data", "Host", GUICtrlRead($inputhost)) IniWrite(@ScriptDir & "\Config.ini", "Data", "Username", GUICtrlRead($inputusername)) IniWrite(@ScriptDir & "\Config.ini", "Data", "Password", GUICtrlRead($inputpassword)) Case $btnload EndSwitch WEnd Edited November 28, 2013 by fikri1979 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 28, 2013 Moderators Share Posted November 28, 2013 fikri1979,Look at FileOpenDialog and FileSaveDialog in the Help file. But note that @WorkingDir is changed after each use of these functions, so you might need to change it back using FileChangeDir. M23 fikri1979 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
fikri1979 Posted November 28, 2013 Author Share Posted November 28, 2013 fikri1979, Look at FileOpenDialog and FileSaveDialog in the Help file. But note that @WorkingDir is changed after each use of these functions, so you might need to change it back using FileChangeDir. M23 how to bring it in inputbox automatically when file select? can give me example? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 28, 2013 Moderators Share Posted November 28, 2013 fikri1979, how to bring it in inputbox automatically when file selectThe 2 dialogs return the selected file name - so store it in a variable and use GUICtrlSetData to put it into the input. Try and code it yourself and see how you get on - come back if you run into difficulties. M23 fikri1979 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
l3ill Posted November 28, 2013 Share Posted November 28, 2013 (edited) Hi fikri1979, Just as an additional tip that might eventually save you some time and trouble. The IniRead and IniWrite functions will automatically save to the ini file without the use of the save and open dialog boxes. Just tie the Iniread with GUICtrlSetData function to your load button and the iniwrite with GUICtrlRead to the save button. Bill Edited November 28, 2013 by billo My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
fikri1979 Posted November 28, 2013 Author Share Posted November 28, 2013 (edited) Hi fikri1979, Just as an additional tip that might eventually save you some time and trouble. The IniRead and IniWrite functions will automatically save to the ini file without the use of the save and open dialog boxes. Just tie the Iniread with GUICtrlSetData function to your load button and the iniwrite with GUICtrlRead to the save button. Bill thanks for the suggestion, but I want to save the file more than one file as shown below for example : 1. 2. when the load file "1.ini" it will show the data in a form that has been stored previously 3. 4. when the load file '2.ini" it will show the data in a form that has been stored previously 5. Edited November 28, 2013 by fikri1979 Link to comment Share on other sites More sharing options...
fikri1979 Posted November 29, 2013 Author Share Posted November 29, 2013 fikri1979, Look at FileOpenDialog and FileSaveDialog in the Help file. But note that @WorkingDir is changed after each use of these functions, so you might need to change it back using FileChangeDir. M23 i have tried like this scrip below...how to fix it button load and use file open dialog? when click button load will appear data in inputbox expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $readproxy Global $readportproxy Global $readhost Global $readporthost Global $readusername Global $readpassword #Region ### START Koda GUI section ### $formdata = GUICreate("data", 350, 280, 200, 114) GUISetBkColor(0xC0DCC0) $server = GUICtrlCreateGroup("Server", 8, 8, 225, 97) $inputhost = GUICtrlCreateInput($readhost, 88, 32, 137, 21) $Label1 = GUICtrlCreateLabel("Host", 24, 32, 26, 17) $Label2 = GUICtrlCreateLabel("Port", 24, 64, 23, 17) $inputporthost = GUICtrlCreateInput($readporthost, 88, 64, 137, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group1 = GUICtrlCreateGroup("User", 8, 112, 225, 97) $Label3 = GUICtrlCreateLabel("Username", 24, 136, 52, 17) $inputusername = GUICtrlCreateInput($readusername, 88, 136, 137, 21) $Label4 = GUICtrlCreateLabel("Password", 24, 168, 50, 17) $inputpassword = GUICtrlCreateInput($readpassword, 88, 168, 137, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("Proxy", 8, 216, 225, 49) $inputproxy = GUICtrlCreateInput("127.0.0.1", 88, 232, 137, 21) $Label5 = GUICtrlCreateLabel("Proxy", 16, 232, 30, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $btnsimpan = GUICtrlCreateButton("SIMPAN", 248, 240, 89, 25) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $btnload = GUICtrlCreateButton("LOAD", 248, 200, 89, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Group3 = GUICtrlCreateGroup("Akun", 248, 8, 89, 177) $AkunRadio1 = GUICtrlCreateRadio("Akun1", 256, 32, 65, 17) $AkunRadio2 = GUICtrlCreateRadio("Akun2", 256, 56, 65, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnsimpan save() Case $btnload load() EndSwitch WEnd Func save() If GUICtrlRead($AkunRadio1) = $gui_checked Then ;jika diklik radio button1 mka akan tersimpan di file config.ini IniWrite(@ScriptDir & "\Config.ini", "Data", "Host", GUICtrlRead($inputhost)) IniWrite(@ScriptDir & "\Config.ini", "Data", "Port Host", GUICtrlRead($inputporthost)) IniWrite(@ScriptDir & "\Config.ini", "Data", "Proxy", GUICtrlRead($inputproxy)) IniWrite(@ScriptDir & "\Config.ini", "Data", "Username", GUICtrlRead($inputusername)) IniWrite(@ScriptDir & "\Config.ini", "Data", "Password", GUICtrlRead($inputpassword)) EndIf If GUICtrlRead($AkunRadio2) = $gui_checked Then ;;jika diklik radio button2 mka akan tersimpan di file config2.ini IniWrite(@ScriptDir & "\Config2.ini", "Data", "Host", GUICtrlRead($inputhost)) IniWrite(@ScriptDir & "\Config2.ini", "Data", "Port Host", GUICtrlRead($inputporthost)) IniWrite(@ScriptDir & "\Config2.ini", "Data", "Proxy", GUICtrlRead($inputproxy)) IniWrite(@ScriptDir & "\Config2.ini", "Data", "Username", GUICtrlRead($inputusername)) IniWrite(@ScriptDir & "\Config2.ini", "Data", "Password", GUICtrlRead($inputpassword)) EndIf EndFunc Func load() If GUICtrlRead($AkunRadio1) = $gui_checked Then $readproxy = IniRead(@ScriptDir & "\Config.ini", "Data", "Proxy", "NotFound") $readhost = IniRead(@ScriptDir & "\Config.ini", "Data", "Host", "NotFound") $readporthost = IniRead(@ScriptDir & "\Config.ini", "Data", "Port Host", "NotFound") $readusername = IniRead(@ScriptDir & "\Config.ini", "Data", "Username", "NotFound") $readpassword = IniRead(@ScriptDir & "\Config.ini", "Data", "Password", "NotFound") EndIf If GUICtrlRead($AkunRadio2) = $gui_checked Then $readproxy = IniRead(@ScriptDir & "\Config2.ini", "Data", "Proxy", "NotFound") $readhost = IniRead(@ScriptDir & "\Config2.ini", "Data", "Host", "NotFound") $readporthost = IniRead(@ScriptDir & "\Config2.ini", "Data", "Port Host", "NotFound") $readusername = IniRead(@ScriptDir & "\Config2.ini", "Data", "Username", "NotFound") $readpassword = IniRead(@ScriptDir & "\Config2.ini", "Data", "Password", "NotFound") EndIf EndFunc Link to comment Share on other sites More sharing options...
l3ill Posted November 29, 2013 Share Posted November 29, 2013 (edited) Just tie the Iniread with GUICtrlSetData function to your load button going to be the same basic funtion with or without the open dialog... you have radio buttons, why do you still need the file open dialog? with there now being only 2 choices. edit: here is a snippet of mine, might help.... Edited November 29, 2013 by billo fikri1979 1 My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
fikri1979 Posted November 29, 2013 Author Share Posted November 29, 2013 going to be the same basic funtion with or without the open dialog... you have radio buttons, why do you still need the file open dialog? with there now being only 2 choices. edit: here is a snippet of mine, might help.... thank you for your help... it turns out that less is : GUICtrlSetData($inputhost,$readhost) GUICtrlSetData($inputporthost,$readporthost) GUICtrlSetData($inputusername,$readusername) GUICtrlSetData($inputpassword,$readpassword) GUICtrlSetData($inputproxy,$readproxy) but I am still curious about how to use the FileOpenDialog and FileSaveDialog in case like this, if without radiobuttons Link to comment Share on other sites More sharing options...
Solution MHz Posted November 29, 2013 Solution Share Posted November 29, 2013 expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $readproxy Global $readportproxy Global $readhost Global $readporthost Global $readusername Global $readpassword #Region ### START Koda GUI section ### $formdata = GUICreate("data", 350, 280, 200, 114) GUISetBkColor(0xC0DCC0) $server = GUICtrlCreateGroup("Server", 8, 8, 225, 97) $inputhost = GUICtrlCreateInput($readhost, 88, 32, 137, 21) $Label1 = GUICtrlCreateLabel("Host", 24, 32, 26, 17) $Label2 = GUICtrlCreateLabel("Port", 24, 64, 23, 17) $inputporthost = GUICtrlCreateInput($readporthost, 88, 64, 137, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group1 = GUICtrlCreateGroup("User", 8, 112, 225, 97) $Label3 = GUICtrlCreateLabel("Username", 24, 136, 52, 17) $inputusername = GUICtrlCreateInput($readusername, 88, 136, 137, 21) $Label4 = GUICtrlCreateLabel("Password", 24, 168, 50, 17) $inputpassword = GUICtrlCreateInput($readpassword, 88, 168, 137, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("Proxy", 8, 216, 225, 49) $inputproxy = GUICtrlCreateInput("127.0.0.1", 88, 232, 137, 21) $Label5 = GUICtrlCreateLabel("Proxy", 16, 232, 30, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $btnsimpan = GUICtrlCreateButton("SIMPAN", 248, 240, 89, 25) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $btnload = GUICtrlCreateButton("LOAD", 248, 200, 89, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Group3 = GUICtrlCreateGroup("Akun", 248, 8, 89, 177) $AkunRadio1 = GUICtrlCreateRadio("Akun1", 256, 32, 65, 17) $AkunRadio2 = GUICtrlCreateRadio("Akun2", 256, 56, 65, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnsimpan save() Case $btnload load() EndSwitch WEnd Func save() Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; save file dialog $ini_file = FileSaveDialog('Save', @ScriptDir, 'Ini (*.ini)|All (*.*)', 10, 'Config.ini', $formdata) ; check if return is valid If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf ; write to ini file IniWrite($ini_file, "Data", "Host", GUICtrlRead($inputhost)) IniWrite($ini_file, "Data", "Port Host", GUICtrlRead($inputporthost)) IniWrite($ini_file, "Data", "Proxy", GUICtrlRead($inputproxy)) IniWrite($ini_file, "Data", "Username", GUICtrlRead($inputusername)) IniWrite($ini_file, "Data", "Password", GUICtrlRead($inputpassword)) ; restore workingdir FileChangeDir($workingdir) EndFunc Func load() Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; open file dialog $ini_file = FileOpenDialog('Open', @ScriptDir, 'Ini (*.ini)|All (*.*)', 1, 'Config.ini', $formdata) ; check if return is valid If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf ; read from ini file GUICtrlSetData($inputproxy, IniRead($ini_file, "Data", "Proxy", "127.0.0.1")) GUICtrlSetData($inputhost, IniRead($ini_file, "Data", "Host", "")) GUICtrlSetData($inputporthost, IniRead($ini_file, "Data", "Port Host", "")) GUICtrlSetData($inputusername, IniRead($ini_file, "Data", "Username", "")) GUICtrlSetData($inputpassword, IniRead($ini_file, "Data", "Password", "")) ; restore workingdir FileChangeDir($workingdir) EndFunc I modified the load and save functions to use FileOpenDialog and FileSaveDialog. Comments added to help to know what happens at each event. Perhaps not exactly what you may want but may show you how to do it. fikri1979 1 Link to comment Share on other sites More sharing options...
l3ill Posted November 29, 2013 Share Posted November 29, 2013 Glad you got it working! just another side tip: I noticed you saving differnt ini files, you can save several differnt configurations in one ini file. Just change the Section Name. fikri1979 1 My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
fikri1979 Posted November 29, 2013 Author Share Posted November 29, 2013 (edited) expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $readproxy Global $readportproxy Global $readhost Global $readporthost Global $readusername Global $readpassword #Region ### START Koda GUI section ### $formdata = GUICreate("data", 350, 280, 200, 114) GUISetBkColor(0xC0DCC0) $server = GUICtrlCreateGroup("Server", 8, 8, 225, 97) $inputhost = GUICtrlCreateInput($readhost, 88, 32, 137, 21) $Label1 = GUICtrlCreateLabel("Host", 24, 32, 26, 17) $Label2 = GUICtrlCreateLabel("Port", 24, 64, 23, 17) $inputporthost = GUICtrlCreateInput($readporthost, 88, 64, 137, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group1 = GUICtrlCreateGroup("User", 8, 112, 225, 97) $Label3 = GUICtrlCreateLabel("Username", 24, 136, 52, 17) $inputusername = GUICtrlCreateInput($readusername, 88, 136, 137, 21) $Label4 = GUICtrlCreateLabel("Password", 24, 168, 50, 17) $inputpassword = GUICtrlCreateInput($readpassword, 88, 168, 137, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("Proxy", 8, 216, 225, 49) $inputproxy = GUICtrlCreateInput("127.0.0.1", 88, 232, 137, 21) $Label5 = GUICtrlCreateLabel("Proxy", 16, 232, 30, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $btnsimpan = GUICtrlCreateButton("SIMPAN", 248, 240, 89, 25) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $btnload = GUICtrlCreateButton("LOAD", 248, 200, 89, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Group3 = GUICtrlCreateGroup("Akun", 248, 8, 89, 177) $AkunRadio1 = GUICtrlCreateRadio("Akun1", 256, 32, 65, 17) $AkunRadio2 = GUICtrlCreateRadio("Akun2", 256, 56, 65, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnsimpan save() Case $btnload load() EndSwitch WEnd Func save() Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; save file dialog $ini_file = FileSaveDialog('Save', @ScriptDir, 'Ini (*.ini)|All (*.*)', 10, 'Config.ini', $formdata) ; check if return is valid If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf ; write to ini file IniWrite($ini_file, "Data", "Host", GUICtrlRead($inputhost)) IniWrite($ini_file, "Data", "Port Host", GUICtrlRead($inputporthost)) IniWrite($ini_file, "Data", "Proxy", GUICtrlRead($inputproxy)) IniWrite($ini_file, "Data", "Username", GUICtrlRead($inputusername)) IniWrite($ini_file, "Data", "Password", GUICtrlRead($inputpassword)) ; restore workingdir FileChangeDir($workingdir) EndFunc Func load() Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; open file dialog $ini_file = FileOpenDialog('Open', @ScriptDir, 'Ini (*.ini)|All (*.*)', 1, 'Config.ini', $formdata) ; check if return is valid If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf ; read from ini file GUICtrlSetData($inputproxy, IniRead($ini_file, "Data", "Proxy", "127.0.0.1")) GUICtrlSetData($inputhost, IniRead($ini_file, "Data", "Host", "")) GUICtrlSetData($inputporthost, IniRead($ini_file, "Data", "Port Host", "")) GUICtrlSetData($inputusername, IniRead($ini_file, "Data", "Username", "")) GUICtrlSetData($inputpassword, IniRead($ini_file, "Data", "Password", "")) ; restore workingdir FileChangeDir($workingdir) EndFunc I modified the load and save functions to use FileOpenDialog and FileSaveDialog. Comments added to help to know what happens at each event. Perhaps not exactly what you may want but may show you how to do it. very helpful, thank you very much Edited November 29, 2013 by fikri1979 Link to comment Share on other sites More sharing options...
fikri1979 Posted November 29, 2013 Author Share Posted November 29, 2013 Glad you got it working! just another side tip: I noticed you saving differnt ini files, you can save several differnt configurations in one ini file. Just change the Section Name. Good tip, thank you 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