VBA to VB.NET and C# Comparison (.NET)

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.

Math Functions

ActiveX, VBA, or Visual Basic 6

VB.NET and C# equivalent (same unless noted)

+ (addition operator)

+ (addition operator)

- (subtraction operator)

- (subtraction operator)

* (multiplication operator)

* (multiplication operator)

/ (division operator)

/ (division operator)

^ (exponentiation operator)

^ (exponentiation operator)

Abs function

System.Math.Abs function

Atn function

System.Math.Atan function

Cos function

System.Math.Cos function

Exp function

System.Math.Exp function

Log function

System.Math.Log function

Max function

System.Math.Max function

Min function

System.Math.Min function

Mod function

VB.NET

Mod function

C#

% (operator)

VB.NET and C#

System.Math.DivRem function

Sin function

System.Math.Sin function

Sqr function

System.Math.Sqrt function

Conditional and Loop Statements

ActiveX, VBA, or Visual Basic 6

VB.NET and C# equivalent (same unless noted)

Do Until… Loop statement

VB.NET

Do Until... Loop statement

C#

Use do... while statement

Do While… Loop statement

VB.NET

Do While... Loop statement

C#

do... while statement

For Each...Next statement

VB.NET

For Each...Next statement

C#

Foreach and For statements

If… Then… Else...End If statement

VB.NET

If… Then… Else...End If statement

C#

if... else... statement

Select Case statement

VB.NET

Select Case statement

C#

Switch statement

While… Wend statement

VB.NET

While... Wend statement

C#

while... statement

Logic Statements

ActiveX, VBA, or Visual Basic 6

VB.NET and C# equivalent (same unless noted)

= (equal to comparison operator)

VB.NET

= (equal to comparison operator)

C#

== (equal to comparison operator)

<> (not equal to comparison operator)

VB.NET

<> (not equal to comparison operator)

C#

!= (not equal to comparison operator)

< (less than comparison operator)

< (less than comparison operator)

<= (less than or equal to comparison operator)

<= (less than or equal to comparison operator)

> (greater than comparison operator)

> (greater than comparison operator)

>= (greater than or equal to comparison operator)

>= (greater than or equal to comparison operator)

And function

VB.NET

And operator

C#

&& operator

Eqv operator

Not provided, use other bitwise comparison methods instead

Imp operator

Not provided, use = comparison instead

Is operator

VB.NET

object Is object

C#

object is object

IsArray function

VB.NET

IsArray function

or

TypeOf arrayName Is Array comparison

C#

typeof(arrayName) == Array comparison

VB.NET and C#

varName.GetType().IsArray

IsNull function

VB.NET

IsDBNull function

C#

Use == null comparison

Like operator

VB.NET

Like operator

VB.NET and C#

stringVariable.Contains function

Not operator

VB.NET

Not operator

C#

!= (not equal to comparison operator)

Or function

VB.NET

Or function

C#

|| operator

Data Conversion Functions

ActiveX, VBA, or Visual Basic 6

VB.NET and C# equivalent (same unless noted)

Asc function

VB.NET

Asc function

C#

(int)’letter

AutoCAD.Application.ActiveDocument.

Utility.AngleToReal method

Autodesk.AutoCAD.Runtime.Converter.

StringToAngle method

AutoCAD.Application.ActiveDocument.

Utility.AngleToString method

Autodesk.AutoCAD.Runtime.Converter.

AngleToString method

AutoCAD.Application.ActiveDocument.

Utility.RealToString method

Autodesk.AutoCAD.Runtime.Converter.

DistanceToString function

CDbl Function

VB.NET

CDbl function

VB.NET and C#

System.Convert.ToDouble function

Chr function

VB.NET

Chr function

VB.NET and C#

System.Convert.ToChar

CInt Function

VB.NET

CInt function

VB.NET and C#

System.Convert.ToInt16, System.Convert.ToInt32, or System.Convert.ToInt64 function

Fix function

VB.NET

Fix function

VB.NET and C#

System.Convert.ToInt16, System.Convert.ToInt32, or System.Convert.ToInt64 function

Int function

VB.NET

Int function

VB.NET and C#

System.Convert.ToInt16, System.Convert.ToInt32, or System.Convert.ToInt64 function

Str function

VB.NET

Str function

VB.NET and C#

System.Convert.ToString function

StrConv function

VB.NET

StrConv function

VB.NET and C#

System.Text.Encoding.Convert function

Basic String Manipulation Functions

ActiveX, VBA, or Visual Basic 6

VB.NET and C# equivalent (same unless noted)

& operator (concatenate string)

VB.NET

& or + operator

C#

+ operator

Len function

VB.NET

Len function

VB.NET and C#

stringVariable.Length property

Mid function

VB.NET

Mid function

VB.NET and C#

stringVariable.Substring function

Get Input from the AutoCAD Command Prompt Functions

ActiveX, VBA, or Visual Basic 6

VB.NET and C# equivalent (same unless noted)

AutoCAD.Application.ActiveDocument.

Utility.GetAngle method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetAngle function

AutoCAD.Application.ActiveDocument.

Utility.GetCorner method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetCorner function

AutoCAD.Application.ActiveDocument.

Utility.GetDistance method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetDistance function

AutoCAD.Application.ActiveDocument.

Utility.GetEntity method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetEntity function

AutoCAD.Application.ActiveDocument.

Utility.GetInteger method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetInteger function

AutoCAD.Application.ActiveDocument.

Utility.GetKeyword method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetKeyword function

AutoCAD.Application.ActiveDocument.

Utility.GetOrientation method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetAngle function

AutoCAD.Application.ActiveDocument.

Utility.GetPoint method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetPoint function

AutoCAD.Application.ActiveDocument.

Utility.GetReal method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetDouble function

AutoCAD.Application.ActiveDocument.

Utility.GetString method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetString function

AutoCAD.Application.ActiveDocument.

Utility.InitializeUserInput

Autodesk.AutoCAD.EditorInput.

PromptKeywordOptions

Basic AutoCAD Application and Drawing Functions

ActiveX, VBA, or Visual Basic 6

VB.NET and C# equivalent (same unless noted)

AutoCAD.Application.ActiveDocument.

Utility.AngleFromXAxis method

Autodesk.AutoCAD.Geometry.Point2d(point1).

GetVectorTo(point2).Angle property

AutoCAD.Application.ListARX method

Autodesk.AutoCAD.Runtime.SystemObjects.

DynamicLinker.GetLoadedModules function

AutoCAD.Application.LoadARX method

Autodesk.AutoCAD.Runtime.SystemObjects.

DynamicLinker.LoadModule method

AutoCAD.Application.UnloadARX method

Autodesk.AutoCAD.Runtime.SystemObjects.

DynamicLinker.UnloadModule method

AutoCAD.Application.

Documents.Close method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.

CloseAndDiscard method

or

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.

CloseAndSave method

AutoCAD.Application.ActiveDocument.

SendCommand method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.

SendStringToExecute method

AutoCAD.Application.ActiveDocument.

Dictionaries.Add method

VB.NET
C#

AutoCAD.Application.ActiveDocument.

Dictionaries.Item method

VB.NET
C#

AutoCAD.Application.ActiveDocument.

ModelSpace property

VB.NET
C#

AutoCAD.Application.ActiveDocument.

ModelSpace.Item method

VB.NET
C#

AutoCAD.Application.ActiveDocument.

ModelSpace.Count property

VB.NET
C#

AutoCAD.Application.ActiveDocument.

ModelSpace.Add<entityname> method

VB.NET
C#

AutoCAD.Application.ActiveDocument.

ActiveSpace property

VB.NET
C#

AutoCAD.Application.ActiveDocument.

PaperSpace property

VB.NET
C#

AutoCAD.Application.ActiveDocument.

ActiveLayout property

VB.NET
C#

AutoCAD.Application.ActiveDocument.

PurgeAll method

HostApplicationServices.WorkingDatabase.

Purge method

AutoCAD.Application.GetVariable method

Autodesk.AutoCAD.ApplicationServices.Application.

GetSystemVariable function

AutoCAD.Application.MenuBar property

Autodesk.AutoCAD.ApplicationServices.Application.

MenuBar property

AutoCAD.Application.MenuGroup property

Autodesk.AutoCAD.ApplicationServices.Application.

MenuGroups property

AutoCAD.Application.ActiveDocument.

PickfirstSelectionSet property

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

SelectImplied function

AutoCAD.Application.ActiveDocument.

Utility.PolarPoint method

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

AutoCAD.Application.

Preferences property

Autodesk.AutoCAD.ApplicationServices.Application.

Preferences property

AutoCAD.Application.ActiveDocument.

Utility.Prompt method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

WriteMessage method

AutoCAD.Application.Quit method

Autodesk.AutoCAD.ApplicationServices.Application.

Quit method

AutoCAD.Application.ActiveDocument.

SelectionSets.Add method

Not needed/provided

AutoCAD.Application.ActiveDocument.

SelectionSets.SelectionSet.Item method

Autodesk.AutoCAD.EditorInput.SelectionSet.

selectionSet.Item(object) method

AutoCAD.Application.ActiveDocument.

SelectionSets.SelectionSet.Delete method

Autodesk.AutoCAD.EditorInput.SelectionSet.

selectionSet.Item(object).Delete method

AutoCAD.Application.ActiveDocument.

SelectionSets.SelectionSet.SelectOnScreen method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

GetSelection method

AutoCAD.Application.ActiveDocument.

SelectionSets.SelectionSet.Count property

Autodesk.AutoCAD.EditorInput.SelectionSet.

selectionSet.Count property

AutoCAD.Application.ActiveDocument.

SelectionSets.SelectionSet.SelectAtPoint method

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument.Editor.

SelectCrossingWindow method

AutoCAD.Application.SetVariable method

Autodesk.AutoCAD.ApplicationServices.Application.

SetSystemVariable method

AutoCAD.Application.ActiveDocument.

Utility.TranslateCoordinates method

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

AutoCAD.Application.Version property

Autodesk.AutoCAD.ApplicationServices.Application.

Version property

ThisDrawing

Autodesk.AutoCAD.ApplicationServices.Application.

DocumentManager.MdiActiveDocument property

and

HostApplicationServices.WorkingDatabase property

Basic VBA and Visual Basic 6 Functions and Statements

ActiveX, VBA, or Visual Basic 6

VB.NET and C# equivalent (same unless noted)

AppActivate AutoCAD.Application.Caption

function
VB.NET

AppActivate Autodesk.AutoCAD.

ApplicationServices.Application.

MainWindow.Text

VB.NET and C#

Use the Win32 Calls ShowWindow and SetWindowPos

Dir function

System.IO.Directory.Exists function

Error object/method/properties

VB.NET

Error object/method/properties

VB.NET and C#

Try Catch statement with exception handling

Function and End Function keywords

VB.NET

Function and End Function keywords and use Return to return a value

C#

Define a procedure and use return to return a value

Input function

VB.NET

Input method

VB.NET and C#

fileStream.Read method

LBound(arrayName) function

VB.NET

LBound(arrayName) function

VB.NET and C#

arrayName.GetLowerBound function

Line Input function

VB.NET

LineInput method

VB.NET and C#

fileStream.Read method

MsgBox function

MessageBox.Show method

object(n) syntax

VB.NET

object(n) syntax

C#

object[n] syntax

Open function

System.IO.File.Open function

ReDim statement

VB.NET

ReDim arrayName(newSize)

VB.NET and C#

arrayName.Resize

Set statement

Not needed/provided

Shell function

VB.NET

Shell function

VB.NET and C#

System.Diagnostics.Process.Start function

Sub and End Sub keywords

VB.NET

Sub and End Sub keywords

C#

Define a procedure

TypeName function

VB.NET

TypeName function

VB.NET and C#

varName.GetType().Name or

varName.GetType().FullName functions

UBound(arrayName) function

VB.NET

UBound(arrayName) function

VB.NET and C#

arrayName.GetUpperBound function