CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

关于控制用户输入 (VBA/ActiveX)

2023-1-5 02:02| 发布者: admin| 查看: 2114| 评论: 0|来自: AutoCAD

摘要: 可以使用 InitializeUserInput 方法定义关键字或将输入类型限制为用户输入方法。

可以使用该方法定义关键字或将输入类型限制为用户输入方法。InitializeUserInput

use 和参数值与 AutoLISPfunction 类似。可以与以下方法一起使用:,,,,,,, 和 不能与方法一起使用。当用户输入法不返回字符串值时,使用该方法检索字符串值(关键字或任意输入)。initgetInitializeUserInputGetAngleGetCornerGetDistanceGetIntegerGetKeywordGetOrientationGetPointGetRealInitializeUserInputGetStringGetInput

该方法接受两个参数。第一个参数是位编码整数值,用于确定用户输入法的输入选项。第二个参数是定义有效关键字的字符串。InitializeUserInput

在 AutoCAD 命令提示符下从用户处获取整数值或关键字

下面的示例提示用户输入正、非负整数值或关键字:

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

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 12:45

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部