请问,在AutoCAD VBA中,怎么选择一个数值并返回此数值到一个变量中?
请问,在AutoCAD VBA中,怎么选择一个数值并返回此数值到一个变量中?同时,当用户选择的不是数值时提示用户重新选择? 你所谓选择是不是叫用户输入数值?看cad帮助里面的例子
Sub Example_GetInteger()
' This example returns the integer entered by the user.
Dim returnInt As Integer
' Return the value entered by user. A prompt is provided.
returnInt = ThisDrawing.Utility.GetInteger("Enter an integer: ")
MsgBox "The integer entered was " & returnInt & vbCrLf & _
"(Enter the next value without prompting.)", , "GetInteger Example"
' Return the value entered by user. No prompt is provided.
returnInt = ThisDrawing.Utility.GetInteger()
MsgBox "The integer entered was " & returnInt, , "GetInteger Example"
End Sub
非常感谢yanyanjun999老师的解答!
我是希望在命令行中提示用户可以选择或者输入数值——从AutoCAD中选择一个数值对象(当用户选择的不是数值时提示用户重新选择),同时也允许用户在命令行中直接输入数值。 允许用户输入任何数值(不限于整数)。 如果用户选择一个数值对象,也需要把此数值返回到一个变量中,供后续使用。 首先我也是个大菜鸟,不是老师,要选择double类型的数值可以用GetReal,让用户输入实数
cad帮助里的代码
Sub Example_GetReal()
' This example returns the Real entered by the user.
Dim returnReal As Double
' Return the value entered by user. A prompt is provided.
returnReal = ThisDrawing.Utility.GetReal("Enter an Real: ")
MsgBox "The real entered was " & returnReal & vbCrLf & _
"(Enter the next value without prompting.)", , "GetReal Example"
' Return the value entered by user. No prompt is provided.
returnReal = ThisDrawing.Utility.GetReal()
MsgBox "The real entered was " & returnReal, , "GetReal Example"
End Sub
从命令行中选择一个数值,可以用getkeyword吗,不太清楚。
如果从cad中选择一个数值的话,最好在vba里面用窗体吧。 如何允许用户从AutoCAD中选中数值呢? 选择哪里的数据呢?是指单行或多行文字里面的数据吗,运用选择集啊,然后判断里面的text内容是不是数值 楼主的意思,是不是这样?
Sub tt()
On Error Resume Next
Dim data As Double
Dim obj As AcadText
Dim pt As Variant
ThisDrawing.Utility.GetEntity obj, pt, "请选择!"
While Not IsNumeric(obj.TextString)
MsgBox "该文本不是数值,请重新选择!"
ThisDrawing.Utility.GetEntity obj, pt, "请重新选择!"
Wend
data = Val(obj.TextString)
MsgBox "已存入变量data中,值为:" & data
End Sub
页:
[1]
2