Jump to content

FileSaveDialong Question


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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.
Link to comment
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

Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
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.
Link to comment
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.
Link to comment
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!

Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...