以下代码将要求用户输入一个整数,以在UNITS中设置变量;然后,代码将INSUNITSDEFSOURCE和INSUNITSDEFTARGE变量设置为与输入值相同的整数值。
- Option Explicit
- Public Sub Example_SetVariable()
- Dim retVal As String
- Dim SysvarName As String
- Dim sysVarData As Variant
- Dim DataType As Integer
- ' Set INSUNITS system variable (data type Integer) to 6. NOTE that
- ' you need to declare a variable as the data type of system variable,
- ' assign data to that variable and then make it variant type
- retVal = ThisDrawing.Utility.GetString _
- (1, vbCrLf & "Enter the Value of InsUnits (This will also change InsUnitsDefSource & InsUnitsDefTarget to the same Value): ")
- Dim intData As Integer
- SysvarName = "INSUNITS"
- intData = retVal
- sysVarData = intData ' Integer data
- ThisDrawing.SetVariable SysvarName, sysVarData
-
- ' Check the variable using GetVariable
- sysVarData = ThisDrawing.GetVariable(SysvarName)
- MsgBox SysvarName & " = " & sysVarData, , "SetVariable Example"
- SysvarName = "INSUNITSDEFSOURCE"
- ThisDrawing.SetVariable SysvarName, sysVarData
- SysvarName = "INSUNITSDEFTARGET"
- ThisDrawing.SetVariable SysvarName, sysVarData
- End Sub
不确定这是否是你想要的;但它对阿斯米的评论进行了一些扩展。 |