GetKeyword Method (ActiveX)

Gets a keyword string from the user.

Supported platforms: Windows only

Signature

VBA:

RetVal = object.GetKeyword([Prompt])
object

Type: Utility

The object this method applies to.

Prompt

Access: Input-only; optional

Type: Variant (string)

The text used to prompt the user for input.

Return Value (RetVal)

Type: String

The keyword returned from the user.

Remarks

AutoCAD pauses for user input of a keyword and sets the return value to the keyword that was entered. The Prompt parameter specifies a string that AutoCAD displays before it pauses. The Prompt is optional. The maximum length of the return value is 511 characters.

The AutoCAD user can enter the keyword from the keyboard. The list of keywords that this method will accept is set by a prior call to the InitializeUserInput method. If the user enters a string not specified in the call to InitializeUserInput, AutoCAD displays an error message and tries again (and redisplays the prompt, if one was specified). If the user doesn't enter anything but presses the Enter key, GetKeyword returns an empty string ("") unless the call to InitializeUserInput also disallowed NULL input.

Examples

VBA:

Sub Example_GetKeyword()
    ' This example uses Getkeyword to return a keyword entered by the user.
    ' InitializeUserInput establishes the valid keywords.
    
    AppActivate ThisDrawing.Application.Caption
    
    ' Define the list of valid keywords
    Dim kwordList As String
    kwordList = "Width Height Depth"
    ThisDrawing.Utility.InitializeUserInput 1, kwordList
            
    ' Prompt the user to input any of the keywords. Return "Width", "Height" or "Depth" in
    ' the returnString variable depending on whether the user input "W", "H" or "D".
    Dim returnString As String
    returnString = ThisDrawing.Utility.GetKeyword(vbLf & "Enter a keyword [Height/Width/Depth]: ")
    MsgBox "You entered " & returnString, , "GetKeyword Example"
    
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_GetKeyword()
    ;; This example uses Getkeyword to return a keyword entered by the user.
    ;; InitializeUserInput establishes the valid keywords.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
  
    ;; Define the list of valid keywords
    (setq kwordList "Width Height Depth")
    (vla-InitializeUserInput (vla-get-Utility doc) 1 kwordList)
            
    ;; Prompt the user to input any of the keywords. Return "Width", "Height" or "Depth" in
    ;; the returnString variable depending on whether the user input "W", "H" or "D".
    (setq returnString (vla-GetKeyword (vla-get-Utility doc) "\nEnter a keyword [Height/Width/Depth]: "))
    (alert (strcat "You entered " returnString))
)