terrypin Posted March 12, 2016 Report Share Posted March 12, 2016 I see that the Variable Modify String > Save to Text File does not check whether a file of that name already exists. Do others simply precede the save with If File Exists please? -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
Cory Posted March 12, 2016 Report Share Posted March 12, 2016 What's the problem? If you save and it exists the file is overwritten. If you save and it doesn't exist the file is created.Are you expecting it to warn you if it already exists? Quote Link to comment Share on other sites More sharing options...
terrypin Posted March 12, 2016 Author Report Share Posted March 12, 2016 What's the problem? If you save and it exists the file is overwritten. If you save and it doesn't exist the file is created.Are you expecting it to warn you if it already exists? Yes. Quote Link to comment Share on other sites More sharing options...
Cory Posted March 12, 2016 Report Share Posted March 12, 2016 If the file exists and I don't want it overwritten then I check and prompt the user for action. I try to do these checks early on in the macro. I sometimes also as the user what they want to do, EG rename, overwrite, or append. Quote Link to comment Share on other sites More sharing options...
terrypin Posted March 13, 2016 Author Report Share Posted March 13, 2016 OK, thanks Cory, that's essentially what I've done in this case, directly before the Variable Modify String > Save to Text File. But I was in a hurry and used the GoTo and Label commands which I'm sure is a clumsy way of achieving my simple aim. Apart from making the default of the If Message a No instead of a Yes, is there a neater way? Variable Set String %tFileName% from the clipboard contents If File Exists: "C:\Docs\Maps\GPS+GPX files\From iPhone+iPad\TEMP.txt" If Message "Overwrite?" Goto:Save Else Macro Stop End If End If :Save Variable Modify String: Save %tFileName% to "C:\Docs\Maps\GPS+GPX files\From iPhone+iPad\TEMP.txt" Quote Link to comment Share on other sites More sharing options...
Cory Posted March 13, 2016 Report Share Posted March 13, 2016 I avoid goto. It's considered a bad practice in most cases. In fact it does nothing for your logic. I would probably make custom button labels and make the 'true' button "No" to avoid the lonely Else clause. Then just end the macro therein. Much simpler. If Message "Overwrite?" Macro Stop End If Also I would give the user the opportunity to change the file name. in a loop they can't get out of until they supply a unique name or abort. Quote Link to comment Share on other sites More sharing options...
terrypin Posted March 13, 2016 Author Report Share Posted March 13, 2016 Thanks Cory. --Terry Pinnell, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.