zemkor Posted May 6, 2015 Posted May 6, 2015 (edited) Hello, i have question. How to save and read data from "GUICtrlCreateEdit" to ini file ?. Problem is: IniWrite write only first line of text and IniRead read only first line text.How to do it?Thanks for answer.$text = GUICtrlCreateEdit("Text", 20, 165, 120, 50) Func save() Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; save file dialog $ini_file = FileSaveDialog('Save', @ScriptDir, 'Ini (*.ini)|All (*.*)', 10, 'Config.ini', $Form1) ; 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", "Text", GUICtrlRead($Text)) EndFunc$text = GUICtrlCreateEdit("Text", 20, 165, 120, 50) Func load() ;natiahne nastavenia z .ini Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; open file dialog $ini_file = FileOpenDialog('Open', @ScriptDir, 'Ini (*.ini)|All (*.*)', 1, 'Config.ini', $Form1) ; check if return is valid If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf ; read from ini file GUICtrlSetData($text, IniRead($ini_file, "Data", "Text", "")) EndFuncThis not working, read and write only firt line Edited May 6, 2015 by zemkor
Moderators Melba23 Posted May 6, 2015 Moderators Posted May 6, 2015 zemkor,Replace the EOL with a suitable dummy string (I tend to use "{ENTER}")before saving the string and then replace these dummies with @CRLF when re-reading it from the ini.M23 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
zemkor Posted May 6, 2015 Author Posted May 6, 2015 Melba23Sorry but i dont understand you. Please can you explain ?
Moderators Melba23 Posted May 6, 2015 Moderators Posted May 6, 2015 zemkor,Does this make it clearer?expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $sText = "Line 1" & @CRLF & "Line 2" & @CRLF & "Line 3" $sIniPath = @ScriptDir & "\test.ini" $hGUI = GUICreate("Test", 500, 500) $cEdit = GUICtrlCreateEdit($sText, 10, 10, 200, 200) $cSave = GUICtrlCreateButton("Save", 10, 300, 80, 30) GUICtrlSetState($cSave, $GUI_FOCUS) $cRead = GUICtrlCreateButton("Read", 100, 300, 80, 30) $cCheck = GUICtrlCreateButton("Check", 400, 300, 80, 30) GUICtrlSetState($cCheck, $GUI_DISABLE) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cSave ; Read multiple lines $sOriginal = GUICtrlRead($cEdit) ; Clear edit GUICtrlSetData($cEdit, "") ; Convert EOLs into dummy strings $sConverted = StringReplace($sOriginal, @CRLF, "{ENTER}") ; This is the result MsgBox($MB_SYSTEMMODAL, "Converted before write", $sConverted) ; Which is written tot he ini IniWrite($sIniPath, "Multiline", "Text", $sConverted) ; Allow us to peek inside the ini GUICtrlSetState($cCheck, $GUI_ENABLE) Case $cRead ; Read the strign from the ini $sOriginal = IniRead($sIniPath, "Multiline", "Text", "Houston, we have a problem") ; Convert the dummies back into EOLs $sConverted = StringReplace($sOriginal, "{ENTER}", @CRLF) ; And we get this MsgBox($MB_SYSTEMMODAL, "Converted after read", $sConverted) ; Which we replace in the edit GUICtrlSetData($cEdit, $sConverted) Case $cCheck ; Read the ini content directly $sContent = FileRead($sIniPath) ; See it is all one string with dummies replacing the EOLs MsgBox($MB_SYSTEMMODAL, "Read from ini", $sContent) EndSwitch WEndPlease ask if anything is still not understood.M23 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
zemkor Posted May 6, 2015 Author Posted May 6, 2015 Huh, your solution working but is much difficult for me. Im newbie . I dont know how used your script for my problem. Can you show me please on my example?expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> $Form1 = GUICreate("TEST read and write", 301, 500, 224, 170) $text = GUICtrlCreateEdit("Text", 20, 165, 200, 300) $load = GUICtrlCreateButton("Load", 170, 41, 121, 33) $save = GUICtrlCreateButton("Save", 170, 89, 121, 33) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $save save() Case $load load() EndSwitch WEnd Func load() ;natiahne nastavenia z .ini Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; open file dialog $ini_file = FileOpenDialog('Open', @ScriptDir, 'Ini (*.ini)|All (*.*)', 1, 'Config.ini', $Form1) ; check if return is valid If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf ; read from ini file GUICtrlSetData($text,IniRead($ini_file, "Data", "Text", "")) ; restore workingdir FileChangeDir($workingdir) EndFunc Func save() Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; save file dialog $ini_file = FileSaveDialog('Save', @ScriptDir, 'Ini (*.ini)|All (*.*)', 10, 'Config.ini', $Form1) ; check if return is valid If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf IniWrite($ini_file, "Data", "Text", GUICtrlRead($text)) FileChangeDir($workingdir) EndFunc
Moderators Melba23 Posted May 6, 2015 Moderators Posted May 6, 2015 zemkor,Only 2 lines need changing - is the concept that hard to grasp?expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> $Form1 = GUICreate("TEST read and write", 301, 500, 224, 170) $text = GUICtrlCreateEdit("Text", 20, 165, 200, 300) $load = GUICtrlCreateButton("Load", 170, 41, 121, 33) $save = GUICtrlCreateButton("Save", 170, 89, 121, 33) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $save save() Case $load load() EndSwitch WEnd Func load() ;natiahne nastavenia z .ini Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; open file dialog $ini_file = FileOpenDialog('Open', @ScriptDir, 'Ini (*.ini)|All (*.*)', 1, 'Config.ini', $Form1) ; check if return is valid If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf ; read from ini file GUICtrlSetData($text, StringReplace(IniRead($ini_file, "Data", "Text", ""), "{ENTER}", @CRLF)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; restore workingdir FileChangeDir($workingdir) EndFunc ;==>load Func save() Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; save file dialog $ini_file = FileSaveDialog('Save', @ScriptDir, 'Ini (*.ini)|All (*.*)', 10, 'Config.ini', $Form1) ; check if return is valid If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf IniWrite($ini_file, "Data", "Text", StringReplace(GUICtrlRead($text), @CRLF, "{ENTER}")) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< FileChangeDir($workingdir) EndFunc ;==>saveM23 satanttin 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
Moderators Melba23 Posted May 6, 2015 Moderators Posted May 6, 2015 zemkor,Glad I could help.M23 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
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