jguinch Posted August 29, 2013 Share Posted August 29, 2013 Hi ! I see a strange behavior with IniWriteSection when I specify a string in the "data" parameter. So I just want to report the problem. I hope it will help...For example, IniWriteSection ($ini, "MySection", "MyKey=MyValues" & @LF & "MyKey2") The result is : [MySection]MyKey=MyValuesMyKey2 I thought the function should return 0 and @ error = 1, but the line is recorded as what (without the = sign), and cannot be removed using IniDelete(). Another example : IniWriteSection ($ini, "MySection", "MyKey1=WillBeDeletedNextTime" & @LF & "MyKey2") IniWriteSection ($ini, "MySection", "MyKey1=MyValues2" & @LF & "MyKey2") The result is : [MySection] MyKey2=MyValues2MyKey2 MyKey2 Two lines were created... Another example : IniWriteSection ($ini, "MySection", "MyKey1=MyValue1" & @LF & "MyKey1=MyValue2") The result is : [MySection]MyKey1=MyValue1MyKey1=MyValue2 Both keys have been created with the same name. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
JohnOne Posted August 29, 2013 Share Posted August 29, 2013 (edited) So this "IniWriteSection ($ini, "MySection", "MyKey1=MyValues2" & @LF & "MyKey2")" Creates this [MySection] MyKey2=MyValues2 Sorry I just don't believe you. EDIT: I misread, and thought you claimed it to be writing "MyKey2" when you specified "MyKey1" Edited August 29, 2013 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 29, 2013 Moderators Share Posted August 29, 2013 jguinch,I can confirm your results using both 3.3.8.1 and 3.3.9.18. It looks like the function does not do a great deal of errorchecking on the input and relies on the user passing a valid string/array. I suggest you create a Trac ticket and see what the Dev team come back with. 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 Link to comment Share on other sites More sharing options...
NewPlaza Posted August 29, 2013 Share Posted August 29, 2013 Yes BUT AutoIt can't check what strings you want to save to a file. Link to comment Share on other sites More sharing options...
jguinch Posted August 29, 2013 Author Share Posted August 29, 2013 Thank you for confirming. @NewPlaza : ok, but the function should return 0 and @ error = 1, rather than do anything Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
BrewManNH Posted August 29, 2013 Share Posted August 29, 2013 You're telling it to put a LineFeed in between your values for the key, it's valid to have that in an INI file. but AutoIt doesn't handle multiline key/values in an ini file. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
jguinch Posted August 29, 2013 Author Share Posted August 29, 2013 Yes, I know that. In fact, the helpfile says that (for IniWrite): Multi-line values are not possible. Well, since it is impossible, the line should not be written, and the return value should be 0 and @error = 1. In the IniWriteSection help, we can read : If the data is a string, then each key=value pair must be delimited by @LF [...] The function will set @error to 1 if the data format is invalid. For me, the function does not sufficiently control the "data" parameter. I still send a Trac ticket to the dev team, I'll see. Thank you for your suggestions Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
JohnOne Posted August 29, 2013 Share Posted August 29, 2013 (edited) Maybe @CRLF then. I dont see any linefeeds between key and value though. EDIT: That @CRLF is probably nonsense I've only used the function with an array. Edited August 29, 2013 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
dragan Posted August 29, 2013 Share Posted August 29, 2013 (edited) You could probably use this workaround: Local $mKey = "MyValues" & @LF & "MyKey2" MsgBox(0, 'Original value', $mKey) $mKey = _ConverCharValues($mKey) IniWrite(@ScriptDir & '\TempINI.ini', 'MySection', 'mKey', $mKey) MsgBox(0, 'Saved INI value', $mKey) $mKey = IniRead(@ScriptDir & '\TempINI.ini', 'MySection', 'mKey', '') $mKey = _ConverCharValues($mKey, True) MsgBox(0, 'Read INI value', $mKey) Func _ConverCharValues($String, $Restore = False) If $String = '' then Return '' If $Restore = False Then Local $__Split = StringSplit($String, '') Local $__retVal = '' For $i = 1 to $__Split[0] $__retVal &= AscW($__Split[$i]) & ',' Next $__retVal = StringTrimRight($__retVal, 1) Return $__retVal Else If NOT StringInStr($String, ',') Then Return ChrW($String) Else Local $__Split = StringSplit($String, ',') Local $__retVal = '' For $i = 1 to $__Split[0] $__retVal &= ChrW($__Split[$i]) Next Return $__retVal EndIf EndIf EndFunc Edited August 29, 2013 by dragan Link to comment Share on other sites More sharing options...
guinness Posted August 29, 2013 Share Posted August 29, 2013 I've never understood why it has to be @LF and not @CRLF. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
BrewManNH Posted August 29, 2013 Share Posted August 29, 2013 IniFiles seem to be created in AutoIt with CRLF line endings. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
guinness Posted August 29, 2013 Share Posted August 29, 2013 Which is kind of why I think it's slightly confusing. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 29, 2013 Moderators Share Posted August 29, 2013 Hi,Looking at the WritePrivateProfileString function on MSDN I imagine that the IniWriteSection function merely splits the string (@LF was chosen for some reason) and then calls the function for each of the resulting elements that it supposes is a key=value pair. I think that it is the failure of this second split that is causing the problem - if you use "MyKey2=" there is no problem.Incidentally, you can reassign the key (even without the =) using IniWrite - so I am even more convinced that it is a problem with the "second split" within IniWriteSection. 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 Link to comment Share on other sites More sharing options...
NewPlaza Posted August 29, 2013 Share Posted August 29, 2013 Thank you for confirming. @NewPlaza : ok, but the function should return 0 and @ error = 1, rather than do anything But why? AutoIt was successful in creating the keys/values you coded. Link to comment Share on other sites More sharing options...
TheSaint Posted August 30, 2013 Share Posted August 30, 2013 I guess one could mount an argument, that an error should be reported if @LF or @CRLF are found in an IniWrite line? On the negative side of that though, is that you would need to test for it and make Ini writing less forgiving than it is. I can just imagine, if you are near the beginning of a lot of Ini writing, where this could be more trouble than you want. As Melba23 said though, for IniWriteSection, you have added an extra delimiter .... but clearly not given what is required to mark what follows it as a key or value. On top of that, the array would would have a count, which you've added to, but it doesn't know that. Perhaps it should automatically assume 'Key', if no equal sign is detected? The data for IniWriteSection is clearly allowed to have @LF, so what you added wouldn't be detected as an error. Or perhaps an error for lack of equal sign? P.S. Don't mind my crossed out musings. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
jguinch Posted August 30, 2013 Author Share Posted August 30, 2013 Thanks everybody for your answers. The function is supposed to return an error when the format of the "data" parameter is incorrect.Maybe it's me who did not express myself well (French), but it disturbs me.I do not want to pollute this great forum, so I stop here.Thank you very much for your opinion. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF 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