On Error Resume Next

On Error Resume Next

bob_clark5J5M8
Contributor Contributor
356 Views
2 Replies
Message 1 of 3

On Error Resume Next

bob_clark5J5M8
Contributor
Contributor

Hi all, I have a piece of code that shows a dialogue box to select a folder and enter a file name. My problem is that it uses the "On error resume next" line of code to function correctly.

 

I'd like to remove this line and still trap the error if someone cancels out of the save or does not enter a file name.

 

'define the active document
oDoc = ThisDoc.Document

'create a file dialog box
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)

'set the directory to open the dialog at
oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()

'set the file name string to use in the input box
oFileDlg.FileName = iProperties.Value("Project", "Part Number")

'work with an error created when cancelling the save
oFileDlg.CancelError = True
On Error Resume Next

'specify the file dialog as a save dialog 
oFileDlg.ShowSave()

'catch an empty string in the input
If Err.Number <> 0 Then
Return
ElseIf oFileDlg.FileName <> "" Then
f = oFileDlg.FileName

'save the file
oDoc.SaveAs(f, False) 
End If

 

0 Likes
Accepted solutions (1)
357 Views
2 Replies
Replies (2)
Message 2 of 3

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @bob_clark5J5M8 

 

I think this will work.  I didn't test well, so post back if it does not

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'define the active document
oDoc = ThisDoc.Document

'create a file dialog box
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)

'set the directory to open the dialog at
oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()

'set the file name string to use in the input box
oFileDlg.FileName = iProperties.Value("Project", "Part Number")

oFileDlg.ShowSave()

'catch an empty string in the input
If oFileDlg.FileName = Nothing Then
	msgbox("no file selected")
	Return
ElseIf oFileDlg.FileName <> "" Then	
	MsgBox("selected: " & oFileDlg.FileName)
	'save the file
	oDoc.SaveAs(oFileDlg.FileName, False)
End If

 

EESignature

0 Likes
Message 3 of 3

bob_clark5J5M8
Contributor
Contributor

Perfect 🙂