bovanshi Posted August 28, 2011 Posted August 28, 2011 (edited) Hi, I have been working on a program which among other things should save a string from a gui edit field to a ini file. Which is later loaded back to the edit field. Since it is not possible to use line feeds in ini files I had to replace them with a string. When loading the string again it will not read past the first line feed in the ini file. For example, edit field: this is a test I replace this to be "thisIITIIisIITIIaIITIItest" When reading this back from the ini file I only get the first part of the string, "this". I think it is because the stringsplit uses another text type which when saved keeps this typ. When read the ini file autoit does not like that a value it reads switched text type. Simple program to demontstrate what happens: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 319, 140, 254, 124) $Button1 = GUICtrlCreateButton("save", 32, 88, 129, 33, $WS_GROUP) $Button2 = GUICtrlCreateButton("load", 176, 88, 121, 33, $WS_GROUP) $Edit1 = GUICtrlCreateEdit("", 32, 16, 257, 73, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_VSCROLL)) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### $count = 0 $saving = "" While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 If GUICtrlRead($Edit1) <> "" Then If GUICtrlRead($Edit1) <> "" Then $solution_string = "" $solution = StringSplit(GUICtrlRead($Edit1), Chr(10)) While $count <= $solution[0] $solution_string = $solution_string & $solution[$count] & "IITII" $count += 1 WEnd $solution_string = StringTrimRight($solution_string, 5) $solution_string = StringTrimLeft($solution_string, 6) $saving = $saving & "solution=" & $solution_string & @LF $count = 0 EndIf EndIf IniWriteSection("Test.ini", "test", $saving) Case $Button2 $solution = IniReadSection("Test.ini", "test") $solution_string = "" $solution = StringSplit($solution[1][1], "IITII") While $count <= $solution[0] $solution_string = $solution_string & $solution[$count] & @CRLF $count += 1 WEnd $solution_string = StringTrimRight($solution_string, 1) $solution_string = StringTrimLeft($solution_string, 2) $count = 0 GUICtrlSetData($Edit1, $solution_string) EndSwitch WEnd For some reason the code above adds to many line feeds when loading when typing in what to load in the ini file manually. (for example, adding the string "anotherIITIItest" manually to the ini file) This code is taken from my program and it seems like it is adding the proper amount of line feeds there, but this is a test, so why bother with details. Any help is much appreciated forum test.au3 Edited August 28, 2011 by bovanshi
Moderators Melba23 Posted August 28, 2011 Moderators Posted August 28, 2011 bovanshi,You need to set the "flag" parameter of StringSplit: "flag = 1, entire delimiter string is needed to mark the split". This works for me - look for the <<<<<<<<<< lines as usual: #include <GUIConstantsEx.au3> $Form1 = GUICreate("Form1", 300, 150) $Button1 = GUICtrlCreateButton("Save", 10, 110, 130, 30) $Button2 = GUICtrlCreateButton("Load", 160, 110, 130, 30) $Edit1 = GUICtrlCreateEdit("", 10, 10, 280, 90) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Button1 If GUICtrlRead($Edit1) <> "" Then $solution = StringSplit(GUICtrlRead($Edit1), @CRLF, 1) ; @CRLF is 2 chars <<<<<<<<<<<<<<<<<<<<<<<<<< $solution_string = $solution[1] For $i = 2 To $solution[0] $solution_string &= "IITII" & $solution[$i] Next EndIf IniWrite("Test.ini", "test", "solution", $solution_string) Case $Button2 $solution = IniRead("Test.ini", "test", "solution", "") If $solution Then $solution = StringSplit($solution, "IITII", 1) ; And here you have 5 chars <<<<<<<<<<<<<<<<<<<<<<<< $solution_string = $solution[1] For $i = 2 To $solution[0] $solution_string &= @CRLF & $solution[$i] Next GUICtrlSetData($Edit1, $solution_string) EndIf EndSwitch WEndI also streamlined the loops a bit. Please ask if anything is unclear. 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
bovanshi Posted August 28, 2011 Author Posted August 28, 2011 (edited) Nice, it works now, thanks! I now realise how much I suck at programming, your code is soo much nicer than mine The rest of my code is about as clear and well designed as this XD Now if you could clean up the rest of my messy program ;P Edited August 28, 2011 by bovanshi
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