benjamindh Posted December 10, 2021 Share Posted December 10, 2021 Hello everyone, I have a problem with an INI file, it happens that this INI file is all saved in a different format, when using the iniwrite it writes it differently in this way [RESOLUTION] and the values in this way screen_x = 1324 screen_x = 680, adding the = sign then saving it doesn't work for me, but removing the = sign and the braces works perfectly, I attached ini file format # # RESOLUTION # screen_x 1324 screen_y 680 fullscreen 0 func Ini() $Rlargo = GUICtrlRead($r_largo) $Rancho = GUICtrlRead($r_ancho) IniWrite("Config.ini","# RESOLUTION","screen_x", $Rlargo) IniWrite("Config.ini","# RESOLUTION","screen_y", $Rancho) EndFunc Link to comment Share on other sites More sharing options...
Developers Jos Posted December 10, 2021 Developers Share Posted December 10, 2021 The shown fileformat for that ini file is invalid and not the standard format use in Windows. The IniRead & IniWrite us the standard Windows format. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
benjamindh Posted December 10, 2021 Author Share Posted December 10, 2021 How would it be to solve this problem or does it not exist in autoit? Link to comment Share on other sites More sharing options...
Developers Jos Posted December 10, 2021 Developers Share Posted December 10, 2021 Maybe you need to start with defining exactly what the file needs to look like, but if it is anyway close to what you posted then you need to write your own functions for reading and writing the file as it isn't the standard Windows format which looks like: [topic] Field=value Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
benjamindh Posted December 10, 2021 Author Share Posted December 10, 2021 this way the original file looks, so with the 2 inputs I need to load the values and save them in the same format Link to comment Share on other sites More sharing options...
Developers Jos Posted December 10, 2021 Developers Share Posted December 10, 2021 So as stated: write some logic to open the file and read the records into variables. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ad777 Posted December 10, 2021 Share Posted December 10, 2021 (edited) try this code it may help ya Global $ste = 1 IniFileWrite("Config.ini","[","RESOLUTION","]","screen_x","=","1324") Func IniFileWrite($Filer,$Brace,$section,$Brace2,$keyr,$Equal,$value) $File = FileReadToArray($Filer) $File = @extended For $i = 0 To $File Step 1 $i = $i + 1 if FileReadLine($Filer,$i)= $Brace&$section&$Brace2 Then $ste = 0 FileWrite($Filer,$keyr&$Equal&$value&@CRLF) Else if $ste = 1 Then FileWriteLine($Filer,$Brace&$section&$Brace2 &@CRLF&$keyr&$Equal&$value&@CRLF) ExitLoop EndIf EndIf Next EndFunc -> Edited December 10, 2021 by ad777 iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. Link to comment Share on other sites More sharing options...
Luke94 Posted December 10, 2021 Share Posted December 10, 2021 You can read this: Quote # # RESOLUTION # screen_x 1324 screen_y 680 fullscreen 0 With: #include <File.au3> #include <String.au3> Local $aLines[0] _FileReadToArray(@ScriptDir & '\Config.ini', $aLines, 0) Local $sScreenX, $sScreenY, $sFullscreen For $i = 0 To (UBound($aLines) - 1) Step 1 If StringLeft($aLines[$i], 8) = 'screen_x' Then $sScreenX = StringStripWS(StringRight($aLines[$i], (StringLen($aLines[$i]) - 8)), $STR_STRIPLEADING + $STR_STRIPTRAILING) ElseIf StringLeft($aLines[$i], 8) = 'screen_y' Then $sScreenY = StringStripWS(StringRight($aLines[$i], (StringLen($aLines[$i]) - 8)), $STR_STRIPLEADING + $STR_STRIPTRAILING) ElseIf StringLeft($aLines[$i], 10) = 'fullscreen' Then $sFullscreen = StringStripWS(StringRight($aLines[$i], (StringLen($aLines[$i]) - 10)), $STR_STRIPLEADING + $STR_STRIPTRAILING) EndIf Next ConsoleWrite('screen_x: ' & $sScreenX & @CRLF) ConsoleWrite('screen_y: ' & $sScreenY & @CRLF) ConsoleWrite('fullscreen: ' & $sFullscreen & @CRLF) Not pretty like.. Link to comment Share on other sites More sharing options...
benners Posted December 10, 2021 Share Posted December 10, 2021 Don't know if this is what you mean. It writes the values to the ini file in the format you supplied, not a default ini format. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> $Form1 = GUICreate("Form1", 255, 96, 1384, 290) $Button1 = GUICtrlCreateButton("Button1", 56, 40, 137, 25) $r_largo = GUICtrlCreateInput("", 24, 8, 100, 21) $r_ancho = GUICtrlCreateInput("", 128, 8, 100, 21) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 WriteToIni() EndSwitch WEnd Func WriteToIni() Local $as_Ini = 0 Local $s_IniFile = @ScriptDir & '\Config.ini' _FileReadToArray($s_IniFile, $as_Ini) For $i = 1 To $as_Ini[0] If StringInStr($as_Ini[$i], 'screen_x') Then $as_Ini[$i] = StringRegExpReplace($as_Ini[$i], '[\d-]+$', GUICtrlRead($r_largo)) If StringInStr($as_Ini[$i], 'screen_y') Then $as_Ini[$i] = StringRegExpReplace($as_Ini[$i], '[\d-]+$', GUICtrlRead($r_ancho)) Next _FileWriteFromArray($s_IniFile, $as_Ini, 1) EndFunc ;==>Ini Config.ini Link to comment Share on other sites More sharing options...
benjamindh Posted December 10, 2021 Author Share Posted December 10, 2021 It does not work for me, I have these 2 inputs where I load the ini information when executing the script, as you can see in the image it presents the error because it needs the = sign but as I mentioned before the ini format of the application that I use does not use the = sign Quote #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 319, 119, 192, 124) $Input1 = GUICtrlCreateInput("", 24, 24, 121, 21) $Input2 = GUICtrlCreateInput("", 160, 24, 121, 21) $Button1 = GUICtrlCreateButton("Save", 24, 56, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Link to comment Share on other sites More sharing options...
benners Posted December 10, 2021 Share Posted December 10, 2021 Have you tried the code? There are no downloads for the config.ini and I made a quick gui based on what I could gather from your posts. Post your full code. So if I understand correctly, you want to load the ini values into the inputs, and write them when the button is clicked? Do you want the format the same as you posted, or a standard ini file? Link to comment Share on other sites More sharing options...
benjamindh Posted December 10, 2021 Author Share Posted December 10, 2021 config.ini this is the original ini file Link to comment Share on other sites More sharing options...
benners Posted December 10, 2021 Share Posted December 10, 2021 Using the file you posted which should be in the same dir as the script I can get the inputs to load and any saved values written to the file. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> $Form1 = GUICreate("Form1", 255, 96, 1384, 290) $Button1 = GUICtrlCreateButton("Guardar", 56, 40, 137, 25) $r_largo = GUICtrlCreateInput("", 24, 8, 100, 21) $r_ancho = GUICtrlCreateInput("", 128, 8, 100, 21) ReadFromINI() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 WriteToIni() EndSwitch WEnd Func WriteToIni() Local $as_Ini = 0 Local $s_IniFile = @ScriptDir & '\Config.ini.txt' _FileReadToArray($s_IniFile, $as_Ini) For $i = 1 To $as_Ini[0] If StringInStr($as_Ini[$i], 'screen_x') Then $as_Ini[$i] = StringRegExpReplace($as_Ini[$i], '[\d-]+$', GUICtrlRead($r_largo)) If StringInStr($as_Ini[$i], 'screen_y') Then $as_Ini[$i] = StringRegExpReplace($as_Ini[$i], '[\d-]+$', GUICtrlRead($r_ancho)) Next _FileWriteFromArray($s_IniFile, $as_Ini, 1) EndFunc ;==>Ini Func ReadFromINI() Local $as_Ini = 0 Local $s_IniFile = @ScriptDir & '\Config.ini.txt' _FileReadToArray($s_IniFile, $as_Ini) For $i = 1 To $as_Ini[0] If StringInStr($as_Ini[$i], 'screen_x') Then GUICtrlSetData($r_largo, StringRegExp($as_Ini[$i], '[\d-]+$', $STR_REGEXPARRAYMATCH)[0]) If StringInStr($as_Ini[$i], 'screen_y') Then GUICtrlSetData($r_ancho, StringRegExp($as_Ini[$i], '[\d-]+$', $STR_REGEXPARRAYMATCH)[0]) Next EndFunc Luke94 1 Link to comment Share on other sites More sharing options...
benjamindh Posted December 10, 2021 Author Share Posted December 10, 2021 error Link to comment Share on other sites More sharing options...
benjamindh Posted December 10, 2021 Author Share Posted December 10, 2021 Thank you very much, it worked for me excellent work. 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