Gets a string from the user.
Supported platforms: Windows only
Signature
VBA:
RetVal = object.GetString(HasSpaces [, Prompt])
- object
-
Type: Utility
The object this method applies to.
- HasSpaces
-
Access: Input-only
Type: Long
- 0: The return string cannot contain spaces. It is terminated by a carriage return or space.
- 1: The return string can contain spaces. It is terminated by a carriage return only.
- Prompt
-
Access: Input-only; optional
Type: Variant (string)
The text used to prompt the user for input.
Return Value (RetVal)
Type: String
The string returned from the user.
Remarks
AutoCAD pauses for user input of the string, and sets the result to the string that the user enters. The HasSpaces parameter specifies whether the string can contain spaces. The Prompt parameter specifies a string that this method displays before AutoCAD pauses.
The AutoCAD user can enter the string from the keyboard. If the HasSpaces parameter is True, the string can contain blanks and the user must terminate it by entering [Return]. If HasSpaces is False, entering either a blank or [Return] terminates the string. If the user enters more than 132 characters, string entry continues until the user enters a blank or carriage return (according to HasSpaces), but GetString places only the first 132 characters into the return value.
Examples
VBA:
Sub Example_GetString() ' This example demonstrates different ways of returning a string ' entered by a user. AppActivate ThisDrawing.Application.Caption Dim returnString As String ' Prompt & Input cannot contain blanks returnString = ThisDrawing.Utility.GetString(False, "Enter text (a space or terminates input): ") MsgBox "The string entered was '" & returnString & "'", , "GetString Example" ' Prompt & Input can contain blanks returnString = ThisDrawing.Utility.GetString(True, "Enter text ( terminates input):") MsgBox "The string entered was '" & returnString & "'", , "GetString Example" ' Prompt & Input can contain blanks, but not an empty string Dim NoNull As Integer NoNull = 1 ' Disallow null ThisDrawing.Utility.InitializeUserInput NoNull returnString = ThisDrawing.Utility.GetString(True, "Enter text ( terminates input): ") MsgBox "The string entered was '" & returnString & "'", , "GetString Example" End Sub
Visual LISP:
(vl-load-com) (defun c:Example_GetString() ;; This example demonstrates different ways of returning a string ;; entered by a user. (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) ;; Prompt & Input cannot contain blanks (setq returnString (vla-GetString (vla-get-Utility doc) :vlax-false "Enter text (a space or <enter> terminates input): ")) (alert (strcat "The string entered was '" returnString "'")) ;; Prompt & Input can contain blanks (setq returnString (vla-GetString (vla-get-Utility doc) :vlax-true "Enter text (<enter> terminates input):")) (alert (strcat "The string entered was '" returnString "'")) ;; Prompt & Input can contain blanks, but not an empty string (setq NoNull 1) ;; Disallow null (vla-InitializeUserInput (vla-get-Utility doc) NoNull) (setq returnString (vla-GetString (vla-get-Utility doc) :vlax-true "Enter text (<enter> terminates input): ")) (alert (strcat "The string entered was '" returnString "'")) )