DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Press Enter to Continue, Esc to Cancel

Started by Mark Laing, February 10, 2011, 08:07:46 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mark Laing

I want a simpe one or two line code fragment to allow exiting a macro or continueing in the macro. The sys function below looks like exactly what I want but I can't imagine how it works. Has anyone here ever used it or anything like it? I doubt this is all that unusual a piece of code.

999 - INPUT Exit condition: 0 for Enter or OK; 1 for Esc or Cancel

As always, thanks in advance. I couldn't do much without you guys.

Rob S

In the dimension scaling macro we had, I used the following code to get text size from user, and exit if the user typed a "0"

prompt$ = "DCAD Version is ", sys$(105),",  Enter desired Text size, Current Text Size is ", sys(12),",  Enter 0 to end"

Input [prompt$], ts

if ts = 0 then end
User since forever

Lar

#2
Mark,

Far as I understand sys(999) means that the cancel button was clicked by the user after the input box appeared on screen. So in the code below if the user clicks cancel the macro will terminate.

Input "Enter desired text size or click cancel to end..." ts
if sys(999) then end



You can also use message boxes, like below:

sys(1027)=3  'message box style = Yes/No/Cancel

message "Group ID = ",groupid,". Solid ID = ",solidid,". Is this the correct group? [you can click Cancel to Abort]..."

'the button that is clicked goes into sys(1028) [1=OK, 2=Cancel, 3=Abort, 4=Retry, 5=Ignore, 6=Yes, 7=No]...
'if the Cancel button is clicked...
if sys(1028)=2 then End
'if the No button is clicked...
if sys(1028)=7 then goto location1       'location1 is a label somewhere else in the bigger code...

'if the Yes button is clicked...
if sys(1028)=6 then goto location2       'location2 is a label somewhere else in the bigger code...

'return to default message type just in case...
sys(1027)=0  'message box style = OK (default)


Also, pressing Enter is equivalent to clicking OK, and pressing Esc is equivalent to clicking Cancel

Lar





paulerens

I think this is the explanation.

Input "What's your name?", name$
if Sys(999) = 1 then   
   Message "User pressed Escape!"
endif

paulerens

#4
Or, so it is more clear.

Input "What's your name?", name$
if Sys(999) = 1 then                                        'If you press Cancel
  Message "User pressed Escape or Cancel!"
Else
 Message,name$
endif

Lar

#5
Ok, I never used it like this but sys(999) holds 0 if the user does Ok/Enter or it holds 1 if the user does Cancel/Esc. So having this info the macro can follow a certain path.

But if you simply want the macro to end if the user clicks cancel (eg, the user has lost the value he's supposed to enter in the input box and he has to abort the macro to determine it again) just use:
if sys(999) then end

Lar

paulerens

#6
Lar,
Try this, but for me it does not work!
Input "What's your name?", name$   'Pres Cancel
if Sys(999) Then End   
   Message "User pressed Escape or Cancel!"
Else
Message,name$
endif
End

paulerens

#7
Lar,
Sorry, your application work in only one direction
What if the user performed OK?

999 - INPUT Exit condition: 0 for Enter or OK; 1 for Esc or Cancel


Lar

#8
Paul, if you enter something then click OK the macro will simply continue running. The help does not indicate this but this is how it always worked. If you don't enter anything and click OK the macro will use zero for the value and continue running, if zero is valid. If not valid you will get an error.

Run the following macro. The first time type in a name, press enter and follow the instructions in the messages. The macro will repeat. This time press cancel.


repeat:
Input "What's your name?", name$

if Sys(999) Then End

Message "Name$=",name$,".  Au revoir!"

message "Press ENTER to close this message box then go to Tools  menu. Check if STOP MACRO is black or grayed out. It should be black, indicating that the macro is still running. Press Esc to close the menu... THEN  SET ONE POINT ANYWHERE!!!"

setpoint "Set a point anywhere (this is just to give the user control of the mouse to check the menu)." 1

message "The macro will repeat. This time press CANCEL then check the menu. STOP MACRO will be grayed out, indicating that the macro has stopped running when you pressed Cancel."

goto repeat

End


After entering your name and pressing ENTER you will be allowed to check the Tools menu. STOP MACRO will be black, indicating that the macro is still running. IMPORTANT: after checking the menu set a point for it to continue (the setpoint prompt in the status bar is very easy to ignore so I use a message first). The macro will repeat. This time press CANCEL and check STOP MACRO in the Tools menu. It will be grayed out, which means the macro is no longer running (ie, it stopped running when you pressed CANCEL).

Lar

Mark Laing

Thanks Everyone
So it really is a bit  tricky. I was feeling like such an idiot. I think I'll go with the message box thing instead. It's more versatile so I'm likely to use it more often and get better and better at it.
Thanks again.
Mark.

paulerens

Thank you,
Your Honour highly illustrious Professor Lar.

Paul.

Lar

#11
Thank you, Paul. I humbly and most graciously accept your Doctorate of Honor and the Key to your City.

May I also commend that I admire your ability to translate, fully comprehend and follow to the letter not only English and not only technical English but also the cryptic language of BasicCAD and your prolific implementation of it.

I hereby bestow upon you the Ambassadorship of the BasicCAD Legion and all its rights and privileges thereof.

Prof. Lar, H.H.I.


DrollTroll

#13
Quote from: paulerens on February 11, 2011, 03:23:18 PM
Try this, but for me it does not work!
Input "What's your name?", name$   'Pres Cancel
if Sys(999) Then End   
   Message "User pressed Escape or Cancel!"
Else
Message,name$
endif
End

Paul, remember that there are two kinds of IF statement -- single line and multi-line. Here by putting the END on the same line as IF, you have tried mixing both types, and may get improper results depending on the user's actions.

'single-line IF statement
If Sys(999) Then END

'multi-line IF statement
If Sys(999) Then
 Message "User pressed Esc or Cancel"
 End
Else
 Message name$
End IF
End
25 years with DesignCAD

paulerens