Sign in to follow this  
Followers 0
Clipper34

If Statement

6 posts in this topic

#1 ·  Posted (edited)

Hey guys, i have a question. Here in the code below

$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
$file = FileSaveDialog("Choose a name:", $MyDocsFolder, "Text files(*.txt)", 16)
If $file = 1 Then
    FileSaveDialog("Choose a name:", $MyDocsFolder, "Text files(*.txt)", 16)
    MsgBox(0, "!", "File saved!")
    EndIf
on line 2 at the end after (*.txt)", is 16 and i'm wondering if you can use an if statement for an InputBox comes up to ask you if you wish to overwrite the file. Thanks

Edited by Clipper34

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi. I think you're confusing .. or I'm having hard times understanding what you want to do. If you put a 16.. then the user will be promped to overwrite if the file already exists.. if you don't put it..then there won't be a warning message.

your 'If $file = 1' doesn't make sense.. $file is the full path of the file chosen to be saved.. $file is something like that : "C:\Test\mytextfile.txt"

Edited by MikeP

Share this post


Link to post
Share on other sites

Below is an example of the FileSaveDialog function.

FileSaveDialog ( "title", "init dir", "filter" [, options [, "default name"]] )
And this again
options   [optional]
  2 = Path Must Exist (if user types a path, ending with a backslash)
 16 = Prompt to OverWrite File
And i'm wondering if you can use a serperate if statement to have an prompt for overwriting a file.

Share this post


Link to post
Share on other sites

$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
While 1
$saveOption = InputBox("","Do you wish to be asked to overwrite files (yes/no)?")
If $saveOption = "yes" OR $saveOption = "no" Then
   ExitLoop
Else
   MsgBox(0,"", "Choose yes or no please")
EndIf
WEnd
If $saveOption = "yes" Then
   $saveOption = 16
Else 
   $saveOption = ""
EndIf

$file = FileSaveDialog("Choose a name:", $MyDocsFolder, "Text files(*.txt)", $saveOption)

Share this post


Link to post
Share on other sites

Thanks MikeP i greatly appreciate the help.

Share this post


Link to post
Share on other sites

Another way that asks after the Save dialog is opened and prevents a double prompt (one from your input box, and again from the Save with 16

$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
$file = FileSaveDialog("Choose a name:", $MyDocsFolder, "Text files(*.txt)")
If FileExists($file) then 
    $saveOption = InputBox("","The file already exists." & @CRLF & "Do you wish to overwrite it (yes/no)?")
    If StringUpper($saveOption) = "YES" then 
        ;file saving stuff here with overwrite
    Else
        ;loop back to file save function or cancel here
    EndIf
EndIf

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