Jump to content
Macro Express Forums

Save variable to text file - no existence check?


Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...