Control User Input

AutoCAD ActiveX

 
Control User Input
 
 
 

You can use the InitializeUserInput method to define keywords or restrict the type of input to the user input method. The use and parameter values are similar to the AutoLISP initget function. InitializeUserInput can be used with the following methods: GetAngle, GetCorner, GetDistance, GetInteger, GetKeyword, GetOrientation, GetPoint, and GetReal. InitializeUserInput cannot be used with the GetString method. Use the GetInput method to retrieve the string value (keyword or arbitrary input) when the user input method does not return a string value.

The InitializeUserInput method accepts two parameters. The first parameter is a bit-coded integer value that determines the input options for the user input method. The second parameter is a string that defines the valid keywords.

Get an integer value or a keyword from the user at the AutoCAD command line

The following example prompts the user for a positive, non-negative integer value or a keyword:

Sub Ch3_UserInput()
      
 ' The first parameter of InitializeUserInput (6)
 ' restricts input to positive and non-negative
 ' values. The second parameter is the list of
 ' valid keywords.
 ThisDrawing.Utility.InitializeUserInput 6, "Big Small Regular"
      
 ' Set the prompt string variable
 Dim promptStr As String
 promptStr = vbCrLf & "Enter the size or (Big/Small/<Regular>):"
      
 ' At the GetInteger prompt, entering a keyword or pressing
 ' ENTER without entering a value results in an error. To allow
 ' your application to continue and check for the error
 ' description, you must set the error handler to resume on error.
 On Error Resume Next
      
 ' Get the value entered by the user
 Dim returnInteger As Integer
 returnInteger = ThisDrawing.Utility.GetInteger(promptStr)
      
 ' Check for an error. If the error number matches the
 ' one shown below, then use GetInput to get the returned
 ' string; otherwise, use the value of returnInteger.
      
 If Err.Number = -2145320928 Then
 Dim returnString As String
 Debug.Print Err.Description
 returnString = ThisDrawing.Utility.GetInput()
 If returnString = "" Then        'ENTER returns null string
 returnString = "Regular"     'Set to default
 End If
 Err.Clear
 Else                                 'Otherwise,
 returnString = returnInteger     'Use the value entered
 End If
      
 ' Display the result
 MsgBox returnString, , "InitializeUserInput Example"
      
End Sub