Lord Felix Posted August 9, 2005 Share Posted August 9, 2005 (edited) Sidenote: Ignore the spelling mistake in the title, wasn't paying attention Alright, below is a my function for saving an .ini file. The reason I'm using this is because I want the user to specify where and what he wants to save his/her settings in. I have already coded an open function and its working fine, so here's my problem. Normally when you use the FileSaveDialog the file will automatically save add the .whatevertypeyouwanttosaveas, but it does't seem to hold true for .ini files. For a temporary solution, I manually added .ini to the patch when writing the file. This causes a problem however, becuase whenever the user wants to overwrite a previous setting it ends up as *.ini.ini. Func SaveSettings() $edit1 = GUICtrlRead(15) $edit2 = GUICtrlRead(17) $edit3 = GUICtrlRead(21) $edit4 = GUICtrlRead(23) $edit5 = GUICtrlRead(25) $edit6 = GUICtrlRead(27) $edit7 = GUICtrlRead(30) $edit8 = GUICtrlRead(31) $edit9 = GUICtrlRead(34) $edit10 = GUICtrlRead(39) $edit11 = GUICtrlRead(41) $message = "Save As" $filesave = FileSaveDialog($message, @ScriptDir & "\", "INI (*.ini)", 1 + 16 + 2) If ($filesave <> 1) Then IniWrite($filesave & ".ini", "LoginInfo", "Username", $edit1) IniWrite($filesave & ".ini", "LoginInfo", "Password", $edit2) IniWrite($filesave & ".ini", "TopicInfo", "Thread Link", $edit3) IniWrite($filesave & ".ini", "TopicInfo", "Thread ID", $edit4) IniWrite($filesave & ".ini", "TopicInfo", "Post Link", $edit5) IniWrite($filesave & ".ini", "MessageInfo", "Message", $edit6) IniWrite($filesave & ".ini", "MessageInfo", "Format", $edit7) IniWrite($filesave & ".ini", "MessageInfo", "NonFormat", $edit8) IniWrite($filesave & ".ini", "MessageInfo", "Start No.", $edit9) IniWrite($filesave & ".ini", "MessageInfo", "Start Format", $edit10) IniWrite($filesave & ".ini", "MessageInfo", "End Format", $edit11) EndIf EndFunc Any help would be appriecaiated. Edited August 9, 2005 by Lord Felix Link to comment Share on other sites More sharing options...
Josbe Posted August 9, 2005 Share Posted August 9, 2005 Why not you simply remove this part:IniWrite($filesave & ".ini", "MessageInfo", "End Format", $edit11) AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
Lord Felix Posted August 9, 2005 Author Share Posted August 9, 2005 Why not you simply remove this part:<{POST_SNAPBACK}>If I did the file saves without an extension. I added that in there as a temporary fix. Link to comment Share on other sites More sharing options...
Josbe Posted August 9, 2005 Share Posted August 9, 2005 (edited) If I did the file saves without an extension. I added that in there as a temporary fix.<{POST_SNAPBACK}>I tested this line:$filesave = FileSaveDialog($message, @ScriptDir & "\", "INI (*.ini)", 1 + 16 + 2)And I wrote a name like "myfile" and the file "myfile.ini" was created correctly.Edit: Sorry, that was adding the extension. Edited August 9, 2005 by Josbe AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
Lord Felix Posted August 9, 2005 Author Share Posted August 9, 2005 I tested this line:$filesave = FileSaveDialog($message, @ScriptDir & "\", "INI (*.ini)", 1 + 16 + 2)And I wrote a name like "myfile" and the file "myfile.ini" was created correctly.<{POST_SNAPBACK}>Hmm, I think the error is when it gets to IniWrite(). When I removed the ' & ".ini" ' the file creates without an extension. Otherwise, it creates a file normally when it saves immediately. Link to comment Share on other sites More sharing options...
Danny35d Posted August 9, 2005 Share Posted August 9, 2005 (edited) After this line: $filesave = FileSaveDialog($message, @ScriptDir & "\", "INI (*.ini)", 1 + 16 + 2) Try adding this line: If StringInStr($filesave, ".", 0, -1) Then $filesave = StringMid($filesave, 1, StringInStr($filesave, ".", 0, -1) - 1) It work for me running windows xp sp2 autoit beta .66 Edited August 9, 2005 by Danny35d AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
Josbe Posted August 9, 2005 Share Posted August 9, 2005 Hmm, I think the error is when it gets to IniWrite(). When I removed the ' & ".ini" ' the file creates without an extension. Otherwise, it creates a file normally when it saves immediately.<{POST_SNAPBACK}>No, isn't IniWrite(), really it's the output returned by FileSaveDialog()You need specify the extension, adding: & ".ini"Check this:$filesave = FileSaveDialog($message, @ScriptDir & "\", "INI (*.ini)", 16) MsgBox(0, "", $filesave)$filesave will be the fullpathname without extension. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
Lord Felix Posted August 9, 2005 Author Share Posted August 9, 2005 After this line:$filesave = FileSaveDialog($message, @ScriptDir & "\", "INI (*.ini)", 1 + 16 + 2)Try adding this line:If StringInStr($filesave, ".", 0, -1) Then $filesave = StringMid($filesave, 1, StringInStr($filesave, ".", 0, -1) - 1)It work for me running windows xp sp2 autoit beta .66<{POST_SNAPBACK}>Thanks Danny, that solved the problem. Now there's a small problem when the user decides to cancel selecting a save path. When this happens it creates a blank ini file. Link to comment Share on other sites More sharing options...
Danny35d Posted August 9, 2005 Share Posted August 9, 2005 (edited) Your welcome Lord Felix Before this line: If StringInStr($filesave, ".", 0, -1) Then $filesave = StringMid($filesave, 1, StringInStr($filesave, ".", 0, -1) - 1) Add this line: If @error then Return(0) good luck! Edited August 9, 2005 by Danny35d AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
Lord Felix Posted August 9, 2005 Author Share Posted August 9, 2005 Your welcome Lord FelixBefore this line:If StringInStr($filesave, ".", 0, -1) Then $filesave = StringMid($filesave, 1, StringInStr($filesave, ".", 0, -1) - 1)Add this line:If @error then Return(0)good luck!<{POST_SNAPBACK}>Thanks again . Problem solved. Link to comment Share on other sites More sharing options...
Josbe Posted August 9, 2005 Share Posted August 9, 2005 Thanks again . Problem solved.<{POST_SNAPBACK}>Very well for you, LF.Sorry the confusion. Really FileSaveDialog() don't saves the extension. Important observation that I forgot. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta 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