缺省情况下,如果使用一个没有声明的变量,它将继承“Variant”类型。在模块、窗体和类的通用声明区使用“OptionExplicit”能强制我们必须声明变量后才能使用变量
Option Explicit
Sub test()
X = 5
End Sub
Option Explicit
Sub tst()
TTT = 5
MsgBox TTT
End Sub
'整型
Dim PageNumber As Integer
PageNumber = 84
'长整型
Dim MySalary As Long
MySalary = 123456
'双精度型
Dim HourToLearnVBA As Double
HourToLearnVBA = 36.25
Sub VariableTestC()
Dim N As Double
N = 1.23456789012346
N = 12345678901234.6
End Sub
'布尔类型
Dim ICanLearnThis As Boolean
ICanLearnThis = True
'日期型
Dim XMReleaseDate As Date
XMReleaseDate = "5/19/2006 8:00:00 AM"
'字符型
Dim MYLevelName As String
MYLevelName = "utilElectricity"
'对象型
Dim MyExcelApp As Object
Set MyExcelApp = GetObject(, "Excel.Application")
'Variant
Dim PointArray As Variant
'MicroStation特有的变量类型
'Application(应用)
Dim MSAPP As Application
Set MSAPP = Application
'ActiveDesignFile当前设计文件
'ActiveModelReference当前模型参考
'ActiveSettings 当前设置
'VBProject object & attributes 对象以及属性
'UserName用户名
'取得左、顶、宽和高属性
'DesignFile设计文件
Dim MyDGN As DesignFile
Set MyDGN = Application.ActiveDesignFile
'Author 作者,Client客户,Comments注释,Company公司,KeyWords关键字,Manager管理者,Subject主题,Title标题
'FormatMajorVersion 格式主版本 FormatMinorVersion格式次版本
'Levels层, Models模型, Name 名称,Path 路径
'ModelReference 模型参考
Dim MyModel As ModelReference
Set MyModel = Application.ActiveModelReference
'Level 层
Dim MyLevel As Level
Set MyLevel = Application.ActiveDesignFile.Levels(1)
'Description 描述, ElementColor元素颜色,ElementLineStyle元素线性,ElementLineWeight元素线宽,IsActive是否激活,IsDisplayed是否显示
'IsFrozen是否冻结,IsLocked是否锁定,Name名字,Number层号,Plot光栅绘图
'LineElement线元素
Dim MyLine As Application
Set MyLine = Application.CreateLineElement2(Nothing, Point3dFromXYZ(0, 0, 0), Point3dFromXYZ(4, 5, 6))
Application.ActiveModelReference.AddElement MyLine
'EllipseElement椭圆元素
Dim MyCircle As EllipseElement
Dim RotMatrix As Matrix3d
Set MyCircle = CreateEllipseElement2(Nothing, Point3dFromXYZ(0, 0, 0), 1.5, 1.5, RotMatrix)
Application.ActiveModelReference.AddElement MyCircle
'ArcElement 弧元素
Dim MyArc As ArcElement
Dim RotMatrix As Matrix3d
Set MyArc = CreateArcElement2(Nothing, Point3dFromXYZ(0, 0, 0), 1.75, 1.75, RotMatrix, Radians(45), Radiands(90))
Application.ActiveModelReference.AddElement MyArc
'TextElement文本元素
Dim MyText As TextElement
Dim RotMatrix As Matrix3d
Set MyText = CreateTextElement1(Nothing, "MicroStation VBA", Point3dFromXYZ(0, 0, 0), RotMatrix)
Application.ActiveModelReference.AddElement MyText
'赋值和设置对象
Dim LevelName As String
LevelName = "Element"
Dim EasementLevel As Level
Set EasementLevel = ActiveDesignFile.AddNewLevel(LevelName)
Dim StartPoint(0 To 2) As Double
StartPoi