Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Issue with InputBox Cancel Button

bbrumfield
Advocate

Issue with InputBox Cancel Button

bbrumfield
Advocate
Advocate

Any Help would be appreciated.

 

Trying to clean up some code so that if the user Hits the cancel button rather than inputting a number they will get bounced back to the start, If they were to leave the text field zero the rule below works but if they cancel there is an error :

 

bbrumfield_0-1654130464862.png

 

Width :

Dim dSheetWidth As Double = CInt(InputBox("Enter Material Width (Value Required)", "Sheet Width", 0.00))

If dSheetWidth = 0 Or Nothing
	
	MessageBox.Show("You Must Enter A Sheet Width")
	
	GoTo Width
	
End If

 Thanks,

 

Brent

0 Likes
Reply
Accepted solutions (2)
416 Views
4 Replies
Replies (4)

A.Acheson
Mentor
Mentor
Accepted solution

This was a little trickier than expected but these two samples seem to work. The cancel and close buttons have a string value where as you have declared a double value. Sample 1 sends the string error to a double value which luckily you don't need to use a value of 0. Sample 2 handles the string values first then the double values.

 

Here is a link to sample1

Width :

On Error Resume Next
Dim dSheetWidth As Double = CInt(InputBox("Enter Material Width (Value Required)", "Sheet Width", 0.00))
On Error GoTo 0 'Error handling

If dSheetWidth = 0 Then GoTo Width
	MessageBox.Show(dSheetWidth, "Success")

 

Here is a link to sample2

 

	

Width :
Dim dSheetWidth As Double
Dim sSheetWidth As String = InputBox("Enter Material Width (Value Required)", "Sheet Width", 0.00)
	
If sSheetWidth = vbNullString Then : GoTo Width 'Deal with cancel/close button
ElseIf sSheetWidth <> vbNullString And Not IsNumeric(sSheetWidth)Then : GoTo Width 'Deal with non numeric values
ElseIf sSheetWidth <> vbNullString And IsNumeric(sSheetWidth)Then 'Is a valid double entry 
	dSheetWidth = CInt(sSheetWidth)
	If dSheetWidth = 0 Then : GoTo Width
	Else
		MessageBox.Show(dSheetWidth, "Success")
	End If
End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @bbrumfield 

 

With iLogic, you can put the inputbox in a try/catch to handle the cancel button.

 

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

Dim dSheetWidth As Double
Try
	dSheetWidth = CInt(InputBox("Enter Material Width (Value Required)", "Sheet Width", 0.00))
Catch
	dSheetWidth = 0
End Try

If dSheetWidth = 0 
	MessageBox.Show("You Must Enter A Sheet Width")

	GoTo Width
End If

 

0 Likes

bbrumfield
Advocate
Advocate

Hi Curtis,

 

Thank you! This has solved the Cancel button issue.

 

Brent

0 Likes

bbrumfield
Advocate
Advocate

Hi A.Acheson,

 

Thank you! Both examples work without error.

 

Brent

0 Likes