18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

THE V ISUAL BASIC 6 ENVIRONMENT<br />

Use the following notation for naming variables<br />

and constants:<br />

[][]<br />

describes how the variable is used or<br />

what it contains. The and <br />

portions should always be lowercase, and the<br />

should use mixed case.<br />

Library Name<br />

Prefix<br />

esriGeometry<br />

c<br />

g<br />

m<br />

<br />

stdole<br />

<br />

Library<br />

ESRI Object Library<br />

Standard OLE COM Library<br />

Simple variable data type<br />

Variable scope<br />

constant within a form or class<br />

<br />

public variable defined in a class form or<br />

standard module<br />

private variable defined in a class or form<br />

local variable<br />

Prefix<br />

b<br />

by<br />

d<br />

fn<br />

h<br />

i<br />

l<br />

p<br />

s<br />

Data Type<br />

Boolean<br />

byte or unsigned char<br />

double<br />

function<br />

handle<br />

int (integer)<br />

long<br />

a pointer<br />

string<br />

<br />

<br />

Order of conditional determination<br />

Visual Basic, unlike languages such as C and C++, performs conditional tests on<br />

all parts of the condition, even if the first part of the condition is False. This<br />

means you must not perform conditional tests on objects and interfaces that had<br />

their validity tested in an earlier part of the conditional statement.<br />

' The following line will raise a runtime error if pFoo is NULL.<br />

If ((Not pFoo Is Nothing) And (TypeOf pFoo.Thing Is IBar)) then<br />

End If<br />

' The correct way to test this code is<br />

If (Not pFoo Is Nothing) Then<br />

If (TypeOf pFoo.Thing Is IBar) Then<br />

' Perform action on IBar thing of Foo<br />

End If<br />

End If<br />

Indentation<br />

Use two spaces or a tab width of two for indentation. Since there is always only<br />

one editor for VB code, formatting is not as critical an issue as it is for C++ code.<br />

Default properties<br />

Avoid using default properties except for the most common cases. They lead to<br />

decreased legibility.<br />

Intermodule referencing<br />

When accessing intermodule data or functions, always qualify the reference with<br />

the module name. This makes the code more readable and results in more efficient<br />

runtime binding.<br />

Multiple property operations<br />

When performing multiple operations against different properties of the same<br />

object, use a With … End With statement. It is more efficient than specifying the<br />

object each time.<br />

With frmHello<br />

.Caption = "Hello world"<br />

.Font = "Playbill"<br />

.Left = (Screen.Width - .Width) / 2<br />

.Top = (Screen.Height - .Height) / 2<br />

End With<br />

Arrays<br />

For arrays, never change Option Base to anything other than zero, which is the<br />

default. Use LBound and UBound to iterate over all items in an array.<br />

myArray = GetSomeArray<br />

For i = LBound(myArray) To UBound(myArray)<br />

MsgBox cstr(myArray(i))<br />

Next I<br />

80 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!