iLogic: inputbox cancel

iLogic: inputbox cancel

Anonymous
Not applicable
4,407 Views
12 Replies
Message 1 of 13

iLogic: inputbox cancel

Anonymous
Not applicable

Hi,

 

I'm trying to create a user input, by using the inputbox. But I also want to be able to cancel the operation. I tried writing it like this but no succes! What do i need to change in order to work?

 

This rule cancels always.

uInput = InputBox("Default entry", "Title", sPrefix)

If vbCancel Then
	MsgBox("cancel")
	Return
End If

'*** Rest of the rule***'

 

 

0 Likes
4,408 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable

I also tried it like it works for messagebox:

Q = MessageBox.Show("Question", "Error",MessageBoxButtons.YesNo,MessageBoxIcon.Warning) If Q = vbYes Then 'Action ElseIf Q = vbNo Then Return End If

 

 

 

Inputbox code:

Q = InputBox("Question", "Title", "Default entry")

'Cancel test
If Q = vbCancel Then
	MsgBox("Cancel")
	Return
End If

 

 

But for my inputbox i get this error:

Error in rule: MINI_MASTER_CREATE_DERIVED_PART, in document: Part2

Conversion from string "" to type 'Double' is not valid.

 

 

 

0 Likes
Message 3 of 13

andrewiv
Advisor
Advisor

I believe this is what you're looking for

Q = InputBox("Question", "Title", "Default entry")

'Cancel test
If Q = "" Then
MsgBox("Cancel")
Return
End If

 

Andrew In’t Veld
Designer / CAD Administrator

Message 4 of 13

MechMachineMan
Advisor
Advisor
If the cancel method doesnt work for you, check this link out:
https://msdn.microsoft.com/en-us/library/6z0ak68w(v=vs.90).aspx

This just explains that if the user clicks cancel, a zero length string is returned; ie

If uInput = ""
'The inputbox was cancelled
End If

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 5 of 13

DanSingleton
Advocate
Advocate

Sorry... old threads are old but this is the one Google popped up when I was searching to InputBox iLogic Handle Cancel

 

As I read this, there's no way to distinguish between a "vbCancel" and the user deleting all text in the dialog and clicking OK?

 

The reason I ask is because in the case of a "true cancel", I'd want to keep the existing value or use the default value but in the case of a user-specified empty string I would want to use that to set the value to an empty string. I guess that's not possible?

 

Guess I'll have to write code to check for the empty string/cancel and then "double-check" the user really wanted to use that before applying the empty string. O_o

0 Likes
Message 6 of 13

MechMachineMan
Advisor
Advisor

Just add text to let your user know that if they proceed with "0" or some other arbitrary string typed into the input box, it will make reset it to a blank string.

 

ie; add an else if clause to your box for the case you want the field to be empty.

 

 

r = InputBox("Choose: Type '0' to reset to blank field")

 

If r = "0"

    value = ""

else if r = ""

    Exit Sub

else

    value = r

End if


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 7 of 13

RoyWickrama_RWEI
Advisor
Advisor

It is strange that "CENCEL" button does not respond.

 

'To FIX Eng. Approved Date
oEngApprovedDate = iProperties.Value(oModelDoc, "Status", "Eng. Approved Date")
iProperties.Value("Status", "Eng. Approved Date") = oEngApprovedDate

oEngApprovedDate = InputBox("ENG. APPROVED DATE: ", "Eng. Approved Date", (oEngApprovedDate))


iProperties.Value("Status", "Eng. Approved Date") = oEngApprovedDate
iProperties.Value(oModelDoc, "Status", "Eng. Approved Date") = oEngApprovedDate

 

I tried several options in vain.

So, decided to seek help from the forum.

 

Could someone help me. Thanks.

0 Likes
Message 8 of 13

Curtis_Waguespack
Consultant
Consultant

Hi rwickrama,

 

This should work.

 

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

 

'To FIX Eng. Approved Date
oEngApprovedDate = iProperties.Value(oModelDoc, "Status", "Eng. Approved Date")
iProperties.Value("Status", "Eng. Approved Date") = oEngApprovedDate

oEngApprovedDate = InputBox("ENG. APPROVED DATE: ", "Eng. Approved Date", (oEngApprovedDate))

If oEngApprovedDate = "" Then
	Return 'exit rule
End If 

iProperties.Value("Status", "Eng. Approved Date") = oEngApprovedDate
iProperties.Value(oModelDoc, "Status", "Eng. Approved Date") = oEngApprovedDate

EESignature

Message 9 of 13

RoyWickrama_RWEI
Advisor
Advisor

Thanks Curtis.

 

This cancel button is a problem always. In case I hit "CANCEL" the following code doesn't go through.

 

Dim oDrawing As DrawingDocument
oDrawing = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim i As Integer
xNOS = oDrawing.Sheets.Count
Err.Number = 0
100:
'myparam = InputBox("Prompt", "Title", "Default Entry")
'catch an empty string in the imput
i = 1
i = InputBox("Prompt", "Title", i)

MessageBox.Show("Message, i = " & i, "Title")
If i = 0 Then Goto 100:
oDrawing.Sheets.Item(i).Activate

I request help.

 

Thanks.

0 Likes
Message 10 of 13

ThomasB44
Mentor
Mentor

As Curtis said in his example code, when you hit cancel in an input box, the returned value is "" even if you have wrote something.

Not "0".

 

So your code should be, for example :

 

SyntaxEditor Code Snippet

Dim oDrawing As DrawingDocument
oDrawing = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim i As Integer
Dim ASheet As String

100:
ASheet = 1
ASheet = InputBox("Prompt", "Title", ASheet)
If ASheet = "" Then Goto 100:

Try
'Convert ASheet string to i number
i = CDblAny(ASheet)
oDrawing.Sheets.Item(i).Activate
Catch
'Sheet number doesn't exists
'Or wrong user entry
MessageBox.Show("Error", "Title")
End Try

 

Hope it helps.


Thomas
Mechanical Designer / Inventor Professional 2025
Inventor Professional EESignature

Message 11 of 13

Curtis_Waguespack
Consultant
Consultant

Hi rwickrama,

 

Here's another variation:

 

 

Dim oDrawing As DrawingDocument
oDrawing = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim i As Integer
xNOS = oDrawing.Sheets.Count

100:
i = 1
Try
    i = InputBox("Prompt", "Title", i)
Catch 
    Goto 100:
End Try

MessageBox.Show("Message, i = " & i, "Title")
oDrawing.Sheets.Item(i).Activate

 

 

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

EESignature

Message 12 of 13

ThomasB44
Mentor
Mentor

Hi @Curtis_Waguespack

Nice tip with your Try/Catch command and the input box cancel button Smiley Wink

It works even if you enter a string value...I haven't think about that, good to know !

My code was too complicated ! Smiley Embarassed

 


Thomas
Mechanical Designer / Inventor Professional 2025
Inventor Professional EESignature

Message 13 of 13

RoyWickrama_RWEI
Advisor
Advisor

Thanks a lot. neat, tiny and perfect.

0 Likes