Aapjuh Posted April 16, 2022 Share Posted April 16, 2022 (edited) Hi, I have a question about what i would take as proper practices in writing to a file like a settings.ini. would it even matter? diskwrites vs diskreads? speed? other reasons? other methods? Does Example1 even actually write when the value is thesame? Example1 (IniRead and IniWrite are incorrect, just an example): $Something_Var01 = IniRead("The settings file and the corresponding value") $Something_Var02 = IniRead("The settings file and the corresponding value") $Something_Var03 = IniRead("The settings file and the corresponding value") $Something_Var04 = IniRead("The settings file and the corresponding value") $Something_Var05 = IniRead("The settings file and the corresponding value") ;...etc ;..do app stuff.. Func _Save_Ini() ;Even if $Var is unchanged from IniRead IniWrite("The settings file and the corresponding",$Something_Var01) IniWrite("The settings file and the corresponding",$Something_Var02) IniWrite("The settings file and the corresponding",$Something_Var03) IniWrite("The settings file and the corresponding",$Something_Var04) IniWrite("The settings file and the corresponding",$Something_Var05) ;...etc Exit EndFunc Example2 (IniRead and IniWrite are incorrect, just an example): $Something_Var01 = IniRead("The settings file and the corresponding value") $Something_Var02 = IniRead("The settings file and the corresponding value") $Something_Var03 = IniRead("The settings file and the corresponding value") $Something_Var04 = IniRead("The settings file and the corresponding value") $Something_Var05 = IniRead("The settings file and the corresponding value") ;...etc ;..do app stuff.. Func _Save_Ini() ;Only if $Var is different from IniRead If $Something_Var01 <> IniRead("The settings file and the corresponding value") Then IniWrite("The settings file and the corresponding",$Something_Var01) If $Something_Var01 <> IniRead("The settings file and the corresponding value") Then IniWrite("The settings file and the corresponding",$Something_Var02) If $Something_Var01 <> IniRead("The settings file and the corresponding value") Then IniWrite("The settings file and the corresponding",$Something_Var03) If $Something_Var01 <> IniRead("The settings file and the corresponding value") Then IniWrite("The settings file and the corresponding",$Something_Var04) If $Something_Var01 <> IniRead("The settings file and the corresponding value") Then IniWrite("The settings file and the corresponding",$Something_Var05) ;...etc Exit EndFunc Edited April 16, 2022 by Aapjuh Link to comment Share on other sites More sharing options...
argumentum Posted April 16, 2022 Share Posted April 16, 2022 I'll give you my 2 cents. My 2 cents is: Do whatever you like. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Nine Posted April 16, 2022 Share Posted April 16, 2022 Worth a few dollars IMO... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Subz Posted April 16, 2022 Share Posted April 16, 2022 Since you're only overwriting the values you can just use IniWrite without the IniRead or use the function more efficiently, for example: _SaveIni("Key1", "ExpectedValue1") _SaveIni("Key2", "ExpectedValue2") _SaveIni("Key3", "ExpectedValue3") Func _SaveIni($_sKey, $_sValue) Local $sFilePath = @ScriptDir & "\FilePath.ini" Local $sSection = "Section" Local $sIniRead = IniRead($sFilePath, $sSection, $_sKey, "") If $sIniRead = $_sValue Then Return IniWrite($sFilePath, $sSection, $_sKey, $_sValue) EndFunc Aapjuh and taurus905 2 Link to comment Share on other sites More sharing options...
taurus905 Posted April 17, 2022 Share Posted April 17, 2022 2 hours ago, Subz said: Since you're only overwriting the values you can just use IniWrite without the IniRead or use the function more efficiently, for example: @SubzThat's a very elegant solution. Saving for future use. Thank you. taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs 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