RvS Posted October 21, 2008 Share Posted October 21, 2008 (edited) Hi, I'm currently trying to create a little GUI for editing a .ini file. What it needs to do is replace the "resolution 800 600" on Line 4 with "resolution $variable" When I use $file = FileOpen("file.ini", 2) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWriteLine($file, "Line1") FileWriteLine($file, "Line2") FileWriteLine($file, "resolution " & $GUI_CBOX_WIDTH) FileClose($file) I used this scrap (which doesnt do what I want but I can write the entire line by myself too, I dont care) It will write me lines, but it will replace the variable with "6" or "1" where I pick 800 600 from the Combobox. Here's the combobox and variables: Global $GUI_CBOX_WIDTH = GUICtrlCreateCombo("Pick a width (pixels)", 112, 240, 121, 25) GUICtrlSetData(-1, $RESOLUTIONS, "") $RESOLUTIONS = "800|1024|1280" Help please =[ Edited October 21, 2008 by RvS Link to comment Share on other sites More sharing options...
komalo Posted October 21, 2008 Share Posted October 21, 2008 (edited) maybe GUICtrlRead . also for writing ini file you can use IniWriteSection and IniWrite functions edit : that's its syntax GUICtrlRead($GUI_CBOX_WIDTH) ; GUICtrlRead with the control id Edited October 21, 2008 by komalo [font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font] Link to comment Share on other sites More sharing options...
RvS Posted October 21, 2008 Author Share Posted October 21, 2008 (edited) The edit: helped me fix the output problem, but Im not sure how to replace Line 4. I have to keep the rest intact: quality 1 screen 1 shadow 1 resolution 800 600 username roger lastname doe I need to keep the rest the same, and only change "800 600" and replace it with whatever I put as variable $GUI_CBOX_WIDTH EDIT: This ini file wont work with: [section] value=1 The structure of lines has to be preserved and it can only make: value 1 Edited October 21, 2008 by RvS Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 21, 2008 Share Posted October 21, 2008 The edit: helped me fix the output problem, but Im not sure how to replace Line 4. I have to keep the rest intact: quality 1 screen 1 shadow 1 resolution 800 600 username roger lastname doe I need to keep the rest the same, and only change "800 600" and replace it with whatever I put as variable $GUI_CBOX_WIDTH EDIT: This ini file wont work with: [section] value=1 The structure of lines has to be preserved and it can only make: value 1 If you know it is always line 4, then you just do this: _FileWriteToLine($file, 4, "resolution " & GUICtrlRead($GUI_CBOX_WIDTH), 1). If not, read the whole file into a string, edit the string, then write it back to the file. If you want to get tricky, read the file to an array, search the array for the old value and change it, then write just that element or the whole array back to the file. You have lots of options here. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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