Sign in to follow this  
Followers 0
Lord Felix

FileSaveDialong Question

11 posts in this topic

#1 ·  Posted (edited)

Sidenote: Ignore the spelling mistake in the title, wasn't paying attention :dance:

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. :whistle:

Edited by Lord Felix

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Josbe

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#9 ·  Posted (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 by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

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!

<{POST_SNAPBACK}>

Thanks again :whistle:. Problem solved.

Share this post


Link to post
Share on other sites

Thanks again  :dance:. Problem solved.

<{POST_SNAPBACK}>

Very well for you, LF.

Sorry the confusion. Really FileSaveDialog() don't saves the extension. Important observation that I forgot. :whistle:

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0