Jump to content
Server Maintenance This Week. ×

exit script if error


This topic is 6468 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi, I have a script that exports records to a csv file. after it has exported it displays an OK dialog.

The problem is that sometimes the previously exported file might be open already, thus resulting in the "file could not be created on this disk". It then proceeds to the OK dialog.

How can I exit the script once this error comes up, instead of it coming up with the OK dialog? or make it display a "process failed, please rerun" dialog?

thanks

Link to comment
Share on other sites

This is default Windows Reaction to when you try to overwrite a currently open file -- nothing to do with FM. You might script the death of that file before exporting using VBScript. Try the following... put this in a field:

Dim wsh, appRunning

Set wsh = CreateObject("Wscript.Shell")

appRunning = True

Do While appRunning = True

appRunning = wsh.AppActivate("[color:red]My CSV file.csv")

If appRunning Then

Wscript.Sleep 200 'give time for focus shift

wsh.SendKeys "%{F4}"

End If

WScript.Sleep 500

Loop

This code will kill any open application with that red part in the title.

So export the field contents where you store the above code to a .vbs file, and run after export -- this effectively closes the open csv document before you run your export script -- hence preventing any errors.

Other than that... your stuck with it.

Link to comment
Share on other sites

Check out the Set Error Capture script statement.

This allows you to trap for errors that would ordinarily display as the dialog box you describe - but you must take control in your script.

Link to comment
Share on other sites

thanks for the reply, i can't fit the vb script in a field though, i have tried to create a calculation field that brings in two fields that make up the two halfs of the script. But i can't get that to work. How do i go about fitting it in?

many thanks, apologies if its a blatantly obvious answer but my knoweldge is still quite sketchy in the basic aspects of FM.

Link to comment
Share on other sites

I am so confused... what do you mean you can't fit it? Just copy the code, and paste it into a field (it doesn't matter if it doesnt "visually fit").

Then export that field to a file with a .vbs extension and turn on execute after export or whatever

Link to comment
Share on other sites

oh yeah, i was thinking of the default calculated field value. thanks a lot it works!

is there any way to kill the "do you want to save changes" dialog when it tries to close the file?

cheers

Link to comment
Share on other sites

This topic is 6468 days old. Please don't post here. Open a new topic instead.

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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.