Sign in to follow this  
Followers 0
MyEarth

[BUG] FileSaveDialog extension

23 posts in this topic

#1 ·  Posted (edited)

With FileSaveDialog using multiple extension, how can i know what is the extension selected? I need to make 2 different function based on the extension selected in the dialog, the return value is only the path :sweating:

EDIT: Ticket

http://www.autoitscript.com/trac/autoit/ticket/2648

Edited by MyEarth

Share this post


Link to post
Share on other sites



The return value is the path and file name including extension.

It's a very simple process to get the extension from that, and worth figuring out yourself if you cannot do it after over 2 years here.

StringInStr and StringMid

Or simple StringSplit will suffice.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I don't see any extension, only the pathfilename

$var = FileSaveDialog("Choose a name.", @ScriptDir, "Scripts (*.au3)|Text files (*.txt)", 2, "MYNAME")
If @error Then
    MsgBox(4096, "", "Save cancelled.")
Else
    MsgBox(4096, "", "You chose " & $var)
EndIf
Edited by MyEarth

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Retrieve the extension from the returned file in variable $var by getting the right 4 characters or use

#include <WinAPIShPath.au3>
_WinAPI_PathFindExtension ( $sPath )

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

MyEarth,

The dialog does not add an extension automatically - you still need to do it manually. That is why you do not see an extension. And this is a Windows "feature" - nothing to do with AutoiI. ;)

You need to add some code like this to check if it has been done:

$var = FileSaveDialog("Choose a name.", @ScriptDir, "Scripts (*.au3)|Text files (*.txt)", 2, "MYNAME")
If @error Then
    MsgBox(4096, "", "Save cancelled.")
Else
    Switch StringRight($var, 4)
        Case ".txt", ".au3"
            ; Good extension
        Case Else
            $sExt = InputBox("Add extension", "Please add an extension: '.txt' or '.au3'")
            $var &= $sExt
        EndSwitch
    MsgBox(4096, "", "You chose " & $var)
EndIf
All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

No, i don't belive. Ok i need to set manually the extension and i know, it's not a problem to add $var & $extension

But how i can set it if i don't have any returned value about extension from the FileSaveDialog? How can i know if a user select Scripts (*.au3) or Txt (*.txt)? 

Don't tell me I need to make two dialog, one for filename and one for extension :ermm:

I don't have any extension in the returned value, only:

C:PathMYNAME

Edited by MyEarth

Share this post


Link to post
Share on other sites

No, i don't belive. Ok i need to set manually the extension and i know, it's not a problem to add $var & $extension

But how i can set it if i don't have any returned value from the FileSaveDialog? How can i know if a user select Scripts (*.au3) or Txt (*.txt)? 

Don't tell me I need to make two dialog, one for filename and one for extension :ermm:

And again, i don't have any extension in the returned value, only:

C:PathMYNAME

What is the filename you selected or typed in the FileSaveDialog() box?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

MyEarth,

No, i don't belive

Fine, then you are on your own as far as I am concerned. :bye:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

$var = FileSaveDialog("Choose a name.", @ScriptDir, "Scripts (*.au3)|Text files (*.txt)", 2, "MYNAME")
If @error Then
    MsgBox(4096, "", "Save cancelled.")
Else
    MsgBox(4096, "", "You chose " & $var)
EndIf

2chpa2r.jpg

ip1vsm.jpg

What is the sense to make a multiple choice when i don't know what is the choice? That's all i what to know, what is the extension selected in the combobox and then i'll add it for save the file ( as i have say at the first post two different function based on that choice )

Edited by MyEarth

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Starg thanks that WinAPI function return the extension based on the combobox so without any other solution using the internal FileSaveDialog i'll use that.

But i think ( my opinion, without any offence for anyone ) Jos need to add to the internal FileSaveDialog the extension return value or is useless to add a multiple choice because i don't know what is the user choice from the combobox.

Edited by MyEarth

Share this post


Link to post
Share on other sites

Starg thanks that WinAPI function return the extension based on the combobox so without any other solution using the internal FileSaveDialog i'll use that.

But i think ( my opinion, without any offence for anyone ) Jos need to add to the internal FileSaveDialog the extension return value or is useless to add a multiple choice because i don't know what is the user choice from the combobox.

Understand what you are saying and know what this issue is now. It should be just a matter of setting .lpstrDefExt to "".

Just make a Bugreport and I won't be me making any changes to AutoIt3 core and "only" maintain the SciTE4AutoIt3 and Utilities stuff.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks jos, i'll make the bug report in a couple of hour, i'm outside at this moment.

Share this post


Link to post
Share on other sites

With this Modification, your example will default to the first supplied extension and show "MYNAME.au3" when running your snippet in the FileName field:

$var = FileSaveDialog("Choose a name.", @ScriptDir, "Scripts (*.au3)|Text files (*.txt)", 2, "MYNAME")

When a filename without an extension is provided in the FileName field, the extension is added which is selected in the "Save as Type" dropdownbox to the returned value in $var.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Yes, perfect. Just for understand, for use this modification ( when you done it after the bug report ) i need to download a BETA version? Would be great if i can use it with the stable if is possible, a beta is always a beta. If is it not possible for now i'll use _WinAPI_GetSaveFileName

Share this post


Link to post
Share on other sites

Yes, perfect. Just for understand, for use this modification ( when you done it after the bug report ) i need to download a BETA version? Would be great if i can use it with the stable if is possible, a beta is always a beta. If is it not possible for now i'll use _WinAPI_GetSaveFileName

I have informed Jon about the modification that needs to be made to implement this change, but leave it to him to decide whether or not he wants to make the modification.

So just created the Bug report to get this on record and link to this thread and lets see what happens.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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