VBA 到 VB.NET 和 C# 的比较
 
 

The following table compares VBA functions with the similar VB.NET and C# functions and operators. The ActiveX library is indicated by “AutoCAD.Application” and the .NET Managed library equivalents are indicated by “Autodesk.AutoCAD” and the VB.NET or C# equivalents are listed as a function or operator.

以下表格比较了 VBA 函数与类似的 VB.NET 和 C# 函数和运算符。“AutoCAD.Application”表示 ActiveX 库而“Autodesk.AutoCAD”表示与其等价的 .NET 托管库。而 VB.NET 或 C# 等效项将作为函数或运算符列出。

数学函数

ActiveX, VBA, 或 Visual Basic 6

VB.NET 和 C# 等价项 (除非另外注明否则等价)

+ (addition 加法运算符)

+ (addition 加法运算符)

- (subtraction 减法运算符)

- (subtraction 减法运算符)

* (multiplication 乘法运算符)

* (multiplication 乘法运算符)

/ (division 除法运算符)

/ (division 除法运算符)

^ (exponentiation 求幂运算符)

^ (exponentiation 求幂运算符)

Abs 函数

System.Math.Abs 函数

Atn 函数

System.Math.Atan 函数

Cos 函数

System.Math.Cos 函数

Exp 函数

System.Math.Exp 函数

Log 函数

System.Math.Log 函数

Max 函数

System.Math.Max 函数

Min 函数

System.Math.Min 函数

Mod 函数

VB.NET

Mod 函数

C#

% (运算符)

VB.NET 和 C#

System.Math.DivRem 函数

Sin 函数

System.Math.Sin 函数

Sqr 函数

System.Math.Sqrt 函数

条件和循环语句

ActiveX, VBA, 或 Visual Basic 6

VB.NET 和 C# 等价项 (除非另外注明否则等价)

Do Until…?Loop 语句

VB.NET

Do Until... Loop 语句

C#

Use do... while 语句

Do While…?Loop 语句

VB.NET

Do While... Loop 语句

C#

do... while 语句

For Each...Next 语句

VB.NET

For Each...Next 语句

C#

Foreach and For 语句s

If… Then… Else...End If 语句

VB.NET

If… Then… Else...End If 语句

C#

if... else... 语句

Select Case 语句

VB.NET

Select Case 语句

C#

Switch 语句

While…?Wend 语句

VB.NET

While... Wend 语句

C#

while... 语句

逻辑语句

ActiveX, VBA, 或 Visual Basic 6

VB.NET 和 C# 等价项 (除非另外注明否则等价)

= (等于比较运算符)

VB.NET

= (equal to comparison operator)

C#

== (equal to comparison operator)

<> (不等于比较运算符)

VB.NET

<> (not equal to comparison operator)

C#

!= (not equal to comparison operator)

< (小于比较运算符)

< (less than comparison operator)

<= (小于等于比较运算符)

<= (less than or equal to comparison operator)

> (大于比较运算符)

> (greater than comparison operator)

>= (大于等于比较运算符)

>= (greater than or equal to comparison operator)

And 函数

VB.NET

And 运算符

C#

&& 运算符

Eqv 运算符

Not provided, use other bitwise comparison methods instead

未提供,使用其它的按位比较方法代替

Imp 运算符

Not provided, use = comparison instead

未提供,使用 = 比较运算符代替

Is 运算符

VB.NET

object Is object

C#

object is object

IsArray 函数

VB.NET

IsArray 函数或

TypeOf arrayName Is Array comparison

C#

typeof(arrayName) == Array comparison

VB.NET 和 C#

varName.GetType().IsArray

IsNull 函数

VB.NET

IsDBNull 函数

C#

使用 == null 比较

Like 运算符

VB.NET

Like 运算符

VB.NET 和 C#

stringVariable.Contains 函数

Not 运算符

VB.NET

Not 运算符

C#

!= (不等于比较运算符)

Or 函数

VB.NET

Or 函数

C#

|| 运算符

数据转换函数

ActiveX, VBA, 或 Visual Basic 6

VB.NET 和 C# 等价项 (除非另外注明否则等价)

Asc 函数

VB.NET

Asc 函数

C#

(int)’letter

AutoCAD.Application.ActiveDocument.

Utility.AngleToReal 方法

Autodesk.AutoCAD.Runtime.Converter.

StringToAngle 方法

AutoCAD.Application.ActiveDocument.

Utility.AngleToString 方法

Autodesk.AutoCAD.Runtime.Converter.

AngleToString 方法

AutoCAD.Application.ActiveDocument.

Utility.RealToString 方法

Autodesk.AutoCAD.Runtime.Converter.

DistanceToString 函数

CDbl 函数

VB.NET

CDbl 函数

VB.NET and C#

System.Convert.ToDouble 函数

Chr 函数

VB.NET

Chr 函数

VB.NET and C#

System.Convert.ToChar

CInt 函数

VB.NET

CInt 函数

VB.NET and C#

System.Convert.ToInt16, System.Convert.ToInt32, or System.Convert.ToInt64 函数

Fix 函数

VB.NET

Fix 函数

VB.NET and C#

System.Convert.ToInt16, System.Convert.ToInt32, or System.Convert.ToInt64 函数

Int 函数

VB.NET

Int 函数

VB.NET and C#

System.Convert.ToInt16, System.Convert.ToInt32, or System.Convert.ToInt64 函数

Str 函数

VB.NET

Str 函数

VB.NET and C#

System.Convert.ToString 函数

StrConv 函数

VB.NET

StrConv 函数

VB.NET and C#

System.Text.Encoding.Convert 函数

基本字符串处理函数

ActiveX, VBA, 或 Visual Basic 6

VB.NET 和 C# 等价项 (除非另外注明否则等价)

& 运算符 (连接字符串)

VB.NET

& 或 + 运算符

C#

+ 运算符

Len 函数

VB.NET

Len 函数

VB.NET and C#

stringVariable.Length 属性

Mid 函数

VB.NET

Mid 函数

VB.NET and C#

stringVariable.Substring 函数

从 AutoCAD 命令提示符中获得输入的函数

ActiveX, VBA, 或 Visual Basic 6

VB.NET 和 C# 等价项 (除非另外注明否则等价)

AutoCAD.Application.ActiveDocument.

Utility.GetAngle 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetAngle 函数

AutoCAD.Application.ActiveDocument.

Utility.GetCorner 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetCorner 函数

AutoCAD.Application.ActiveDocument.

Utility.GetDistance 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetDistance 函数

AutoCAD.Application.ActiveDocument.

Utility.GetEntity 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetEntity 函数

AutoCAD.Application.ActiveDocument.

Utility.GetInteger 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetInteger 函数

AutoCAD.Application.ActiveDocument.

Utility.GetKeyword 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetKeyword 函数

AutoCAD.Application.ActiveDocument.

Utility.GetOrientation 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetAngle 函数

AutoCAD.Application.ActiveDocument.

Utility.GetPoint 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetPoint 函数

AutoCAD.Application.ActiveDocument.

Utility.GetReal 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetDouble 函数

AutoCAD.Application.ActiveDocument.

Utility.GetString 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetString 函数

AutoCAD.Application.ActiveDocument.

Utility.InitializeUserInput

Autodesk.AutoCAD.EditorInput.

PromptKeywordOptions

基本的 AutoCAD 应用程序和图形函数

ActiveX, VBA, 或 Visual Basic 6

VB.NET 和 C# 等价项 (除非另外注明否则等价)

AutoCAD.Application.ActiveDocument.

Utility.AngleFromXAxis 方法

Autodesk.AutoCAD.Geometry.Point2d(point1).

GetVectorTo(point2).Angle 属性

AutoCAD.Application.ListARX 方法

Autodesk.AutoCAD.Runtime.SystemObjects.

DynamicLinker.GetLoadedModules 函数

AutoCAD.Application.LoadARX 方法

Autodesk.AutoCAD.Runtime.SystemObjects.

DynamicLinker.LoadModule 方法

AutoCAD.Application.UnloadARX 方法

Autodesk.AutoCAD.Runtime.SystemObjects.

DynamicLinker.UnloadModule 方法

AutoCAD.Application.

Documents.Close 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.

CloseAndDiscard 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.

CloseAndSave 方法

AutoCAD.Application.ActiveDocument.

SendCommand 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.

SendStringToExecute 方法

AutoCAD.Application.ActiveDocument.

Dictionaries.Add 方法

VB.NET

dictionaryObj = transactionObj.

GetObject(workingDatabaseObj.

NamedObjectsDictionaryId, openMode)

dictionaryObj.SetAt 函数

C#

dictionaryObj = transactionObj.

GetObject(workingDatabaseObj.

NamedObjectsDictionaryId, openMode) as Autodesk.AutoCAD.DatabaseServices.

DBDictionary;

dictionaryObj.SetAt 函数

AutoCAD.Application.ActiveDocument.

Dictionaries.Item 方法

VB.NET

dictionaryObj = transactionObj.

GetObject(workingDatabaseObj.

NamedObjectsDictionaryId, openMode)

dictionaryObj.GetAt 函数

C#

dictionaryObj = transactionObj.

GetObject(workingDatabaseObj.

NamedObjectsDictionaryId, openMode) as Autodesk.AutoCAD.DatabaseServices.

DBDictionary;

dictionaryObj.GetAt 函数

AutoCAD.Application.ActiveDocument.

ModelSpace 属性

VB.NET

blockTableObj = transactionObj.

GetObject(workingDatabaseObj.BlockTableId, openMode)

blockTableRecordObj = transactionObj.

GetObject(blockTableObj(BlockTableRecord.

ModelSpace), openMode)

C#

blockTableObj = transactionObj.

GetObject(workingDatabaseObj.BlockTableId, openMode) as Autodesk.AutoCAD.

DatabaseServices.BlockTable;

blockTableRecordObj = transactionObj.

GetObject(blockTableObj[BlockTableRecord.

ModelSpace], openMode) as

Autodesk.AutoCAD.DatabaseServices.

BlockTableRecord;

AutoCAD.Application.ActiveDocument.

ModelSpace.Item 方法

VB.NET

blockTableObj = transactionObj.

GetObject(workingDatabaseObj.BlockTableId, openMode)

blockTableRecordObj = transactionObj.

GetObject(blockTableObj(BlockTableRecord.

ModelSpace), openMode)

dbObj = blockTableRecordObj(index)

C#

blockTableObj = transactionObj.

GetObject(workingDatabaseObj.BlockTableId, openMode) as Autodesk.AutoCAD.

DatabaseServices.BlockTable;

blockTableRecordObj = transactionObj.

GetObject(blockTableObj[BlockTableRecord.

ModelSpace], openMode) as

Autodesk.AutoCAD.DatabaseServices.

BlockTableRecord;

foreach(objecId in blockTableRecordObj)

{

objObject = transactionObj.GetObject(objecId);

}

AutoCAD.Application.ActiveDocument.

ModelSpace.Count 属性

VB.NET

blockTableObj = transactionObj.

GetObject(workingDatabaseObj.BlockTableId, openMode)

blockTableRecordObj = transactionObj.

GetObject(blockTableObj(BlockTableRecord.

ModelSpace), openMode)

Dim nCount As Integer = 0

For Each objectId In blockTableRecordObj

nCount = nCount + 1

Next

C#

blockTableObj = transactionObj.

GetObject(workingDatabaseObj.BlockTableId,

openMode) as Autodesk.AutoCAD.

DatabaseServices.BlockTable;

blockTableRecordObj = transactionObj.

GetObject(blockTableObj[BlockTableRecord.

ModelSpace], openMode) as Autodesk.

AutoCAD.DatabaseServices.BlockTableRecord;

int cnt = 0;

foreach(objectId in blockTableRecordObj)

{

cnt = cnt + 1;

}

AutoCAD.Application.ActiveDocument.

ModelSpace.Add<entityname> 方法

VB.NET

blockTableObj = transactionObj.

GetObject(workingDatabaseObj.BlockTableId, openMode)

blockTableRecordObj = transactionObj.

GetObject(blockTableObj(BlockTableRecord.

ModelSpace), openMode)

blockTableRecordObj.AppendEntity(someEntity)

transactionObj.AddNewlyCreatedDBObject(someEntity, True)

C#

blockTableObj = transactionObj.

GetObject(workingDatabaseObj.BlockTableId,

openMode) as Autodesk.AutoCAD.

DatabaseServices.BlockTable;

blockTableRecordObj = transactionObj.

GetObject(blockTableObj[BlockTableRecord.

ModelSpace], openMode) as Autodesk.

AutoCAD.DatabaseServices.BlockTableRecord;

blockTableRecordObj.AppendEntity(someEntity);

transactionObj.AddNewlyCreatedDBObject(someEntity, true);

AutoCAD.Application.ActiveDocument.

ActiveSpace 属性

VB.NET

blockTableRecordObj = transactionObj.

GetObject(workingDatabaseObj.CurrentSpaceId, openMode)

C#

blockTableRecordObj = transactionObj.

GetObject(workingDatabaseObj.CurrentSpaceId,

openMode) as Autodesk.AutoCAD.

DatabaseServices.BlockTableRecord;

AutoCAD.Application.ActiveDocument.

PaperSpace 属性

VB.NET

blockTableObj = transactionObj.

GetObject(workingDatabaseObj.BlockTableId, openMode)

blockTableRecordObj = transactionObj.

GetObject(blockTableObj(BlockTableRecord.

PaperSpace), openMode)

C#

blockTableObj = transactionObj.

GetObject(workingDatabaseObj.BlockTableId, openMode) as Autodesk.AutoCAD.

DatabaseServices.BlockTable;

blockTableRecordObj = transactionObj.

GetObject(blockTableObj[BlockTableRecord.

PaperSpace], openMode) as

Autodesk.AutoCAD.DatabaseServices.

BlockTableRecord;

AutoCAD.Application.ActiveDocument.

ActiveLayout 属性

VB.NET

layoutObj = transactionObj.

GetObject(layoutManagerObj.

GetLayoutId(layoutManagerObj.

CurrentLayout), openMode)

blockTableRecordObj = transactionObj.

GetObject(layoutObj.BlockTableRecordId, openMode)

C#

layoutObj = transactionObj.

GetObject(layoutManagerObj.

GetLayoutId(layoutManagerObj.

CurrentLayout), openMode)

as Autodesk.AutoCAD.

DatabaseServices.Layout;

blockTableRecordObj = transactionObj.

GetObject(layoutObj.BlockTableRecordId,

openMode) as Autodesk. AutoCAD.

DatabaseServices.BlockTableRecord;

AutoCAD.Application.ActiveDocument.

PurgeAll 方法

HostApplicationServices.WorkingDatabase.

Purge 方法

AutoCAD.Application.GetVariable 方法

Autodesk.AutoCAD.ApplicationServices.Application.

GetSystemVariable 函数

AutoCAD.Application.MenuBar 属性

Autodesk.AutoCAD.ApplicationServices.Application.

MenuBar 属性

AutoCAD.Application.MenuGroup 属性

Autodesk.AutoCAD.ApplicationServices.Application.

MenuGroups 属性

AutoCAD.Application.ActiveDocument.

PickfirstSelectionSet 属性

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

SelectImplied 函数

AutoCAD.Application.ActiveDocument.

Utility.PolarPoint 方法

Not provided, use the Point2d and Point3d classes from the Geometry namespace to calculate a new point

未提供,使用 Geometry 命名空间的 Point2d 和 Point3d 类计算新的点

AutoCAD.Application.

Preferences 属性

Autodesk.AutoCAD.ApplicationServices.Application.

Preferences 属性

AutoCAD.Application.ActiveDocument.

Utility.Prompt 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

WriteMessage 方法

AutoCAD.Application.Quit 方法

Autodesk.AutoCAD.ApplicationServices.Application.

Quit 方法

AutoCAD.Application.ActiveDocument.

SelectionSets.Add 方法

Not needed/provided

不需要,未提供

AutoCAD.Application.ActiveDocument.

SelectionSets.SelectionSet.Item 方法

Autodesk.AutoCAD.EditorInput.SelectionSet.

selectionSet.Item(object) 方法

AutoCAD.Application.ActiveDocument.

SelectionSets.SelectionSet.Delete 方法

Autodesk.AutoCAD.EditorInput.SelectionSet.

selectionSet.Item(object).Delete 方法

AutoCAD.Application.ActiveDocument.

SelectionSets.SelectionSet.SelectOnScreen 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetSelection 方法

AutoCAD.Application.ActiveDocument.

SelectionSets.SelectionSet.Count 属性

Autodesk.AutoCAD.EditorInput.SelectionSet.

selectionSet.Count 属性

AutoCAD.Application.ActiveDocument.

SelectionSets.SelectionSet.SelectAtPoint 方法

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

SelectCrossingWindow 方法

AutoCAD.Application.SetVariable 方法

Autodesk.AutoCAD.ApplicationServices.Application.

SetSystemVariable 方法

AutoCAD.Application.ActiveDocument.

Utility.TranslateCoordinates 方法

Not provided, use the Matrix3d class from the Geometry namespace to translate points between different coordinate systems

未提供,使用 Geometry 命名空间的 Matrix3d 类在两个不同的坐标系统中转换点。

AutoCAD.Application.Version 属性

Autodesk.AutoCAD.ApplicationServices.Application.

Version 属性

ThisDrawing

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument 属性

HostApplicationServices.WorkingDatabase 属性

基本的 VBA 和 Visual Basic 6 函数和语句

ActiveX, VBA, or Visual Basic 6

VB.NET 和 C# 等价项 (除非另外注明否则等价)

AppActivate AutoCAD.Application.Caption

函数
VB.NET

AppActivate Autodesk.AutoCAD.

ApplicationServices.Application.

MainWindow.Text

VB.NET 和 C#

使用 Win32 调用 ShowWindow 和 SetWindowPos 函数

Dir 函数

System.IO.Directory.Exists 函数

Error 对象/方法/属性

VB.NET

Error 对象/方法/属性

VB.NET and C#

Try Catch 语句和 异常 处理技术

Function 和 End Function 关键字

VB.NET

Function 和 End Function 关键字并使用 Return 返回一个值

C#

定义一个子过程并使用 return 返回一个值

Input 函数

VB.NET

Input 方法

VB.NET 和 C#

fileStream.Read 方法

LBound(arrayName) 函数

VB.NET

LBound(arrayName) 函数

VB.NET 和 C#

arrayName.GetLowerBound 函数

Line Input 函数

VB.NET

LineInput 方法

VB.NET 和 C#

fileStream.Read 方法

MsgBox 函数

MessageBox.Show 方法

object(n) 语句

VB.NET

object(n) 语法

C#

object[n] 语句

Open 函数

System.IO.File.Open 函数

ReDim 语句

VB.NET

ReDim arrayName(newSize)

VB.NET 和 C#

arrayName.Resize

Set 语句

不需要,未提供

Shell 函数

VB.NET

Shell 函数

VB.NET 和 C#

System.Diagnostics.Process.Start 函数

Sub 和 End Sub 关键字

VB.NET

Sub 和 End Sub 关键字

C#

定义一个过程

TypeName 函数

VB.NET

TypeName 函数

VB.NET 和 C#

varName.GetType().Name 或

varName.GetType().FullName 函数s

UBound(arrayName) 函数

VB.NET

UBound(arrayName) 函数

VB.NET 和 C#

arrayName.GetUpperBound 函数