.NET

Reply
Valued Mentor
ralstogj
Posts: 611
Registered: ‎10-01-2006
Message 1 of 2 (121 Views)

Dealing with Keywords but also alllowing double and return key enter as well

121 Views, 1 Replies
07-11-2012 02:15 PM

Hi

 

I am trying to get my code to work more like some of the built in autocad commands below is the code I have come up with. However if the string returned is not a Keyword or a string that can be converted to a double it is then not acceptable input. How do I jump back to re ask for the input. I could use goto I guess but thats not good practice is there a better way?

 

           

           

'ask the user if they want to accept the sureface level at the lid level or enter a new one

           

Dim acDoc AsDocument = Application.DocumentManager.MdiActiveDocument

           

Dim pKeyOpts AsPromptKeywordOptions = NewPromptKeywordOptions("")

           

Dim CurrentLidLevel AsDouble = oStructure.RimElevation

            pKeyOpts.Message = vbLf &

"Structure Lid Level:" & CurrentLidLevel

            pKeyOpts.Keywords.Add(

"Surface")

            pKeyOpts.Keywords.Add(

"New")

           

'pKeyOpts.Keywords.Default = "New"

            pKeyOpts.AllowNone =

True

           

Dim pKeyRes AsPromptResult = acDoc.Editor.GetKeywords(pKeyOpts)

           

SelectCase pKeyRes.StringResult

               

Case"Surface"

                   

'Do nothing

                    Lidlevel = CurrentLidLevel

               

Case"New"

                   

'ask user for grade to use

                    Lidlevel = acDoc.Editor.GetDouble(vbCrLf &

"Enter New lid level of Structure").Value

               

Case""

                   

'Enter key hit

                    MsgBox(

"using surface level for lid level")

               

Case Else

                   

'Check if input was a number that we can work with

                   

Try

                       

Double.TryParse(pKeyRes.StringResult, Lidlevel)

                   

Catch ex AsException

                   

EndTry

 

 

                   

'enter pressed do nothing

           

EndSelect

 

Regards

Justin Ralston
http://c3dxtreme.blogspot.com/
*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 2 of 2 (114 Views)

Re: Dealing with Keywords but also alllowing double and return key enter as well

07-11-2012 03:16 PM in reply to: ralstogj

Use GetDouble with PromptDoubleOptions and AutoCAD will automatically reprompt if the user enters anything that is not a double or a keyword.  Setting AllowNone = true allows the Enter Key.

Dave O.                                                                  Sig-Logos32.png
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!