IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesC++/CLI  Print This     

C++/CLI and Access VBA Cross Reference Guide

By Mike Prestwood

C++/CLI versus Access VBA: A side by side comparison between C++/CLI and Access VBA.

C++/CLI

This content is based on C++/CLI (C++ for the .Net Framework) and all code was tested in VS.Net 2008 using the various CLR project templates for .Net. The CLI stands for Common Language Infrastructure.

Access VBA

Version: This content is based on Microsoft Access 2003.

This content focuses on topics in common among the languages documented here so this content most likely applies to Access 2007 as well as earlier versions such as Access 97, 2000, and 2002.

In addition, much of the Access information presented here is in common with ASP Classic (with some notable differences) and VB Classic (very closely). Finally, the syntax for VB.Net is based on VB so some of it even applies to VB.Net.

 
Tool Basics
 

Developer environment basics such as common file extensions, common keyboard shortcuts, etc.

Deployment Overview

[Other Languages] 
C++/CLI: 

C++/CLI projects require the .Net framework and any additional dependencies you've added such as Crystal Reports.

In Visual Studio.Net, you can create a Setup and Deployment project by using any of the templates available on the New Project dialog (Other Project Types).

To create a ClickOnce deploy package, search the internet for mage.exe and mageui.exe.

In addition, you can use any of the many free and commercially available installation packages.

More Info / Comment
Access VBA: 

You can deploy your Microsoft Access application either with the full version of Access or with the Access Runtime (see Deploying Applications Using the Access Runtime).

More Info / Comment




Development Tools

[Other Languages] 

Languages Focus

Primary development tool(s) used to develop and debug code.

C++/CLI: 

The only development tool I know that supports C++/CLI at this time is Visual Studio.Net. C++/CLI was introduced in VS.Net 2005 and continued in VS.Net 2008.

More Info / Comment
Access VBA: 

Microsoft Office Access is the primary tool and does include pretty good debugging features, some limited OOP features such as designing a class and instantiating an object, and, best of all, MS still has developers working on MS Access (as opposed to Corel Paradox).

More Info / Comment




File Extensions

[Other Languages] 

Languages Focus

Common or primary file extensions used (not a complete list, just the basics).

C++/CLI:   .CPP and .H

The C++/CLI standard file extensions are the same as standard C++. Important C++ file extensions:

  • .CPP = C++ Source file. Your startup source file will have a main() routine.
  • .C = C source file (sometimes used for C++ source files too).
  • .H = Header include file.

Some important Visual C++ file extensions:

More Info / Comment
Access VBA:   .MDB
  • .MDB - Access Database
  • .MDE - Protected Access Database




Overview and History

[Other Languages] 
C++/CLI: 

Language Overview: Microsoft's C++ language for .Net Framework development. Was called Managed C++ but the name changed after a major overhaul of the language. C++/CLI is a hybrid language that allows you to use standard C++ (callled native objects) as well as managed C++/CLI objects. Whether a type is native or managed within the same appliction depends on whether you use standard C++ syntax or the new C++/CLI managed code syntax.

Language History: C++/CLI was introducted with VS.Net 2005 and replaced Managed C++ (introduced with VS.Net 2002). C++/CLI was standardized by ECMA-372.

Target Platforms: C++/CLI is suitable for creating .Net Framework applications.

More Info / Comment
Access VBA: 

Language Overview: Class-based language. Although you can create classes, Access VBA is not fully OOP. It is a traditional language with a few OOP extensions. You code in a traditional approach using functions, procedures, and global data, and you can make use of simple classes to help organize your reusable code.

Target Platforms: Microsoft Access is most suitable for creating business desktop applications that run within Microsoft Access for Windows.

More Info / Comment




Report Tools Overview

[Other Languages] 

Languages Focus

Built-In: Some development tools have a reporting tool built-in and some do not. For example, typically desktop databases such as Paradox and Access have a built-in reporting tool and typically that reporting tool is used with nearly every application built with it. A built-in reporting tool makes development of reports across many clients and applications consistent and therefore easy.

Add-On: Development tools that do not have a built-in reporting tool need to use either a currently bundled report writer, or one of the popular reporting tools that integrates well with the development tool. For example, popular reporting tools include Crystal Reports, ReportBuilder, and MS SQL Reporting Services (tied to MS SQL).

C++/CLI: 

Use any report writer you are comfortable with but Crystal Reports remains popular for Visual C++ and C++/CLI. For C++Builder, Nevrona Rave Reports remains popular and all editions of C++Builder 2009 come bundled with Rave Reports 7.6 (CodeGear Bundled Edition).

More Info / Comment
Access VBA:   Built-In

Microsoft Access offers a built-in reporting tool that will suffice for most desktop database applications.

More Info / Comment




 
Language Basics
 

Language basics is kind of a catch all for absolute beginner stuff. The items (common names) I chose for language basics is a bit random and include items like case sensitivity, commenting, declaring variables, etc.

Case Sensitivity

[Other Languages] 

Languages Focus

Case sensitiviy in this case is referring to commands and variable names. For example, are "printf" and "PrintF" equivalent? Are fullname and FullName equivalent? When you create commands, operations, methods, or variables should you worry about case?

C++/CLI:   Yes

Same as standard C++. Both are case sensitive. In C and C++ commands and variable names are case sensitive.

Syntax Example:

The following first C++/CLI snippet works:

MessageBox::Show("Hello");
 
messagebox::SHOW("Hello"); //>>>Does not work!
Access VBA:   No

Access VBA is not case sensitive. Like VB Classic, if you type any other case for command or variable names, Access VBA will change it to the "accepted" or "defined" case. For example, if you type msgbox it is converted to Msgbox.

Syntax Example:  

The following code works:

MsgBox ("hello")




Code Blocks

[Other Languages] 

Languages Focus

The rules for code blocks within a language dictate where you can declare variables, how you "bracket" code, etc.

C++/CLI:   { }

Same as standard C++. For C++, Java, JavaScript, and PHP, I prefer to put the first { at the end of the first line of the code block as in the example above because I see more C++ formatted that way.

Syntax Example:
class Cyborg {
public: System::Void IntroduceYourself() {
MessageBox::Show("Hi");
}
};
Access VBA:   End Xxx

Access VBA code blocks are surrounded by statement ending keywords that all use End such as End Sub, End If, and WEnd.

Syntax Example:
Sub x
End Sub
 
If x Then
End If
  
While x
WEnd




Comments

[Other Languages] 

Languages Focus

Commenting code generally has three purposes: to document your code, for psuedo coding prior to coding, and to embed compiler directives. Most languages support both a single line comment and a multiple line comment. Some languages also use comments to give instructions to the compiler or interpreter.

C++/CLI:   // or /* ... */

Commenting Code
Same as standard C++. C++ uses "//" for a single line comment and /* */ for a multiple line comment.

Syntax Example:
//Single line comment in MS (not ANSI compliant so do NOT use).
/* ANSI compliant single line comment. */
/*
Multiple line
comment.
*/
  
/*
* This is another popular
* way to write multi-line
* comments.
*/
Access VBA:   ' or REM

Commenting Code
Access VBA, like all the VB-based languages, uses a single quote (') or the original class-style basic "REM" (most developers just use a quote). Access VBA does NOT have a multiple line comment.

Directives - #

Directives are sometimes called compiler or preprocessor directives. A # is used for directives within Access VBA code. Access VBA offers only an #If..then/#ElseIf/#Else directive.

Syntax Example:
'Single line comment.

REM Old school single line comment.

#If MyDirective Then
'...some code.
#End If




Constants

[Other Languages] 

General Info: Computer Language Constants

A constant is just like a variable (it holds a value) but, unlike a variable, you cannot change the value of a constant.

C++/CLI:   const or literal

C++/CLI supports the const and static const keywords of standard C++ as well as the new literal keyword. A literal is equivalent to static const in standard C++ and Microsoft's documentation recommends to replace static const with the new literal keyword because a literal is available in metadata; a static const variable is not available in metadata to other compilers.

You can use static const within the class declaration or locally within a method. However, literal is only valid in the class declaration section and const is only valid within a method.

Syntax Example:  
//some method {
const String^ MyName = "John";
static const Int32 MyAge = 27;
//}
// public class SomeClass : public Object {
public:
  literal double Pi = 3.14159;
  literal String^ MyName = "Mike";
  static const Int32 MyAge = 35;
//...
Access VBA:   Const kPI = 3.1459

Scope can be Public, Global, or Private. The use of the newer Public keyword is preferred to the older Global. Private Const is the same as just specifying Const.

Syntax Example:
Const kPI = 3.1459
Const kName = "Mike"
 
//Public variable:
Public Const kFeetToMeter=3.28, kMeterToFeet=.3




End of Statement

[Other Languages] 

Languages Focus

In coding languages, common End of statement specifiers include a semicolon and return (others exist too). Also of concern when studying a language is can you put two statements on a single code line and can you break a single statement into two or more code lines.

C++/CLI:   ;

Same as standard C++. C++ uses a semicolon ";" as an end of statement specifier and you can put multiple statements on a single line of code if you wish as well as split a single statement into two or more code lines.

Syntax Example:
//.Net WinForms example.
//Add, using namespace System::Windows::Forms;
MessageBox::Show("Hello1");
MessageBox::Show("Hello2");
MessageBox::Show("Hello3");
   
MessageBox::Show("Hello4"); MessageBox::Show("Hello5"); 
  
MessageBox:: 
  Show 
    ("Hello6");
Access VBA:   Return

A return marks the end of a statement and you cannot combine statements on a single line of code. You can break a single statement into two or more code lines by using a space and underscore " _".

Syntax Example:
MsgBox "Hello1"
MsgBox "Hello2"
MsgBox "Hello3"

'The following commented code on a single line does not work...
'MsgBox "Hello4" MsgBox "Hello5"

'Two or more lines works too with a space+underscore:
MsgBox _
"Hello6";




Literals

[Other Languages] 

General Info: Programming Literals

A value directly written into the source code of a computer program (as opposed to an identifier like a variable or constant). Literals cannot be changed. Common types of literals include string literals, floating point literals, integer literals, and hexidemal literals. Literal strings are usually either quoted (") or use an apostrophe (') which is often referred to as a single quote. Sometimes quotes are inaccurately referred to as double quotes.

Languages Focus

In addition to understanding whether to use a quote or apostrophe for string literals, you also want to know how to specify and work with other types of literals including floating point literals. Some compilers allow leading and trailing decimals (.1 + .1), while some require a leading or trailing 0 as in (0.1 + 0.1). Also, because floating point literals are difficult for compilers to represent accurately, you need to understand how the compiler handles them and how to use rounding and trimming commands correctly for the nature of the project your are coding.

C++/CLI:   qoute

Same as standard C++. String literals are quoted as in "Prestwood". If you need to embed a quote use a slash in front of the quote as in \".

To specify a floating point literal between 1 and -1, you can preceed the decimal with a 0 or not (both work). In other words, preceding and following decimals are allowed (both .1 and 0.1). Trailing decimals are also allowed (1, 1., and 1.0 are all equivalent and allowed).

Syntax Example:
MessageBox::Show("Hello");
MessageBox::Show("Hello \"Mike\".");
  
//Does ASP evaluate this simple
//floating point math correctly? No! 
if ((.1 + .1 + .1) == 0.3) {
MessageBox::Show("Correct");
} else {
MessageBox::Show("Not correct");
}
Access VBA:   quote

String literals are quoted as in "Prestwood". If you need to embed a quote use two quotes in a row.

To specify a floating point literal between 1 and -1, you can preceed the decimal with a 0 or not (both work). In other words, preceding and following decimals are allowed (both .1 and 0.1). Trailing decimals are optimized out and replaced with # if only integer values are used.

Syntax Example:
MsgBox ("Hello")
MsgBox ("Hello ""Mike"".")
 
'Does Access VBA evaluate this simple
'floating point math correctly? No! 
If (.1 + .1 + .1) = 0.3 Then
MsgBox "Correct"
Else
MsgBox "Not correct"
End If




Variables

[Other Languages] 

Languages Focus

A variable holds a value that you can use and change throughout your code so long as the variable is within scope. With variable declaration, you not only want to know the syntax of how you declare a variable but you also want to know where. Are you allowed to declare a variable inline? What are the available scopes: local vs. global. Can you assign a value at the same time you declare a variable?

C++/CLI: 
Access VBA:   Dim x as Integer

Access VBA is a loosely typed language. Declaring variables is optional unless you use the Option Explicit statement to force explicit declaration of all variables with Dim, Private, Public, or ReDim. Using Option Explicit is strongly recommended to avoid incorrectly typing an existing variable and to avoid any confusion about variable scope.

Undeclared variables are variants. To specifically declare a variant, use:

Dim x As Variant
Dim x 

Common data types include Byte (0..255), Boolean, Integer (2-byte integers), Long (4-byte integers), Currency, Single (32-bit number), Double (64-bit number), Date, String, and variant.

Variables declared with Dim at the module level are available to all procedures within the module. At the procedure level, variables are available only within the procedure.

Syntax Example:
Dim FullName As String
Dim Age As Integer
Dim Weight As Double
 
FullName = "Mike Prestwood"
Age = 32
Weight = 154.4
 
'Declaritive assignment not supported:
''Dim Married As String = "Y"   '>>>Not supported.




 
Language Details
 

Language Details is kind of a catch all for stuff that didn't make it into language basics nor any other category.

Custom Routines

[Other Languages] 

Languages Focus

For non-OOP languages, a custom routine is a function, procedure, or subroutine and for pure OOP languages, a custom routine is a class method. Hybrid languages (both non-OOP and OOP) combine both.

[Not specified yet. Coming...]
Access VBA:   Sub, Function

Access VBA is a non-OOP language with some OOP features. It offers both Subs and Functions. A Sub does not return a value while a Function does. When Subs and Functions are used in a class module, they become the methods of the class.

Syntax Example:
Sub SayHello(ByVal pName As String)
  MsgBox ("Hello " & pName)
End Sub
 
Function Add(pN1 As Integer, pN2 As Integer) As Integer
  Add = pN1 + pN2
End Function




Inline Code

[Other Languages] 

Languages Focus

Also known as embedded code where you embed another syntax language within the native code of the development environment you are using. The inline code can be compiled by the current development's compiler or by an external compiler.

Do not confuse with inlining which is a coding technique where custom routines are moved inline where the code is executed either by you, by a compiler directive, or automatically by the compiler.

C++/CLI:   Not Supported

Since all the .Net languages compile into intermediate language (IL), and not to a specific CPU, they do not provide support for inline assembler code.

Access VBA:   Not Supported




Inlining

[Other Languages] 

General Info: Inline Routines

Instead of calling a routine, you move the code from the routine itself and expand it in place of the call. In addition to manual inlining, some languages support automatic inlining where the compiler or some other pre-compiler decides when to inline a code routine. Also, some languages allow for developer defined inlining where the developer can suggest and/or force the inlining of a code routine. Inlining can optimize your code for speed by saving a call and return, and parameter management.

Languages Focus

Does it support inlining? If so, does it support developer defined inlining? Does it support automatic inlining? Both?

C++/CLI:   Automatic

In C++/CLI, inlining is automatically done for you by the JIT compiler for all languages and in general leads to faster code for all programmers whether they are aware of inlining or not.

More Info / Comment
Access VBA:   Not Supported




Overloading

[Other Languages] 

Types of overloading include method overloading and operator overloading.

Method Overloading is where different functions with the same name are invoked based on the data types of the parameters passed or the number of parameters. Method overloading is a type of polymorphism and is also known as Parametric Polymorphism.

Operater Overloading allows an operator to behave differently based on the types of values used. For example, in some languages the + operator is used both to add numbers and to concatenate strings. Custom operator overloading is sometimes referred to as ad-hoc polymorphism.

[Not specified yet. Coming...]
Access VBA:   Not Supported

Some developers like to pass in an array and then handle the array for a pseudo technique but that's not really overloading.





Parameters

[Other Languages] 
[Not specified yet. Coming...]
Access VBA:   ByRef, ByVal

By Reference or Value
For parameters, you can optionally specify ByVal or ByRef. ByRef is the default if you don't specify.

Syntax Example:  
Function SomeRoutine(ByRef pPerson, ByVal pName, Age)




Self Keyword

[Other Languages] 
C++/CLI:   this
Access VBA:   Me

Same as VB. The Me keyword is a built-in variable that refers to the class where the code is executing. For example, you can pass Me from one module to another.

Syntax Example:
Private Sub Command10_Click()
    MsgBox Me.Name 'Displays name of form (Form1 in this case).

End Sub




 
Data Structures
 

Data structures allow you to store and work with data. Common data structures include arrays, associative arrays, etc.

Array

[Other Languages] 

Languages Focus

A data structure in which individual values (called elements or items) may be located by reference to one or more integer index variables, the number of such indices being the number of dimensions in the array.

Arrays can start with an index value of 0 or 1, sometimes referred to as 0 based or 1 based.

[Not specified yet. Coming...]
Access VBA:   x = Array()

Arrays in Access VBA use a 0-based indice. Use UBound to get the number of elements. UBound returns -1 if the array has no elements, 0 if it has 1, 1 if it has 2, etc.

Syntax Example:  
Dim MyArray As Variant
Dim i As Integer
 
MyArray = Array("Mike", "Lisa", "Felicia", "Nathan")
 
If UBound(MyArray) > -1 Then
  For i = 0 To UBound(MyArray)
    MsgBox (MyArray(i))
  Next
End If




Associative Array

[Other Languages] 
A set of unique keys linked to a set of values. Each unique key is associated with a value. Think of it as a two column table. MyArray['CA'] = 'California' MyArray['AR'] = 'Arizona'

Languages Focus

Associative arrays are also known as a dictionary or a hash table in other languages.

[Not specified yet. Coming...]
Access VBA:   Collection

In addition to Add and Item, collections also offer Count and Remove. Notice that Add uses the format of Value, Key (which is backwards from many other languages).

Syntax Example:
Dim States As New Collection
   
States.Add "California", "CA"
States.Add "Nevada", "NV"
    
MsgBox (States.Item("CA"))




Pointers

[Other Languages] 

General Info: Pointers / References

A pointer is a variable type that allows you to refer indirectly to another object. Instead of holding data, a pointer holds the address to data -- the address of another variable or object. You can change the address value a pointer points to thus changing the variable or object the pointer is pointing to.

A reference is a type of pointer that cannot change and it must always point to a valid storage (no nulls).

[Not specified yet. Coming...]
Access VBA:   Not Supported

Same as VB Classic. Access VBA does not offer developer defined pointers.





 
Statements
 

Common statements such as if statements, loops, etc.

If Statement

[Other Languages] 
C++/CLI:   if..else if..else

Same as standard C.

Syntax Example:
int x;
  
x = 8;
  
if (x == 10) {
MessageBox::Show("x is 10");
} else if (x < 10) {
MessageBox::Show("x is less than 10");
} else {
MessageBox::Show("x must be greater than 10");
}
Access VBA:   If..ElseIf..Else..End If

The End If is optional if you put your code on a single line.

Syntax Example:
//Single line example.
If X = True Then MsgBox "hello" 
  
//Complete example. 
If X = True Then
'>>>do something.
ElseIf Y = "ABC" Then
'>>>do something.
Else
'>>>do something.
End If




 
Operators
 

A language symbol used for assignment, comparison, computational, or as a logical.

Assignment

[Other Languages] 

Languages Focus

Common assignment operators for languages include =, ==, and :=. An assignment operator allows you to assign a value to a variable. The value can be a literal value like "Mike" or 42 or the value stored in another variable or returned by a function.

C++/CLI:   =

C++/CLI uses = for it's assignment operator.

Syntax Example:
int Age;
string FullName;
  
Age = 42;
FullName = "Randy Spitz";
Access VBA:   =

Access uses = for it's assignment operator.

Syntax Example:
Dim Age As Integer
Dim FullName As String
   
FullName = "Randy Spitz"
Age = 38




Comparison Operators

[Other Languages] 

General Info: Round Floating Point Numbers

When comparing floating point numbers, make sure you round to an acceptable level of rounding for the type of application you are using.

Languages Focus

A comparison operator compares two values either literals as in "Hello" and 3 or variables as in X and Counter. Most languages use the same operators for comparing both numbers and strings. Perl, for example, uses separate sets of comparison operators for numbers and strings.

C++/CLI:   ==, !=

Same as standard C++. Common comparison operators:

== equal
!= not equal
< less than
> greater than
<= less than or equal
>= greater than or equal
Syntax Example:
//Does C++/CLI evaluate the math correctly? No!
if (0.1 + 0.1 + 0.1 == 0.3)
MessageBox::Show("correct");
else
MessageBox::Show("not correct");
Access VBA:   =, <>

Save as VB Classic. Common comparison operators:

= equal
<> not equal
< less than
> greater than
<= less than or equal
>= greater than or equal

Syntax Example:
//Does Access evaluate the math correctly? No!
If 0.1 + 0.1 + 0.1 = 0.3 Then
MsgBox "correct"
Else
MsgBox "not correct"
End If




Empty String Check

[Other Languages] 

Languages Focus

An empty string is a zero length string, a string that is equal to null (""), or not assigned. In some languages, you can check if a string is empty by comparing it to an empty string (""). Some languages distinguish between nil and null ("") so checking if the length is 0 is easier.

C++/CLI:   String.IsNullOrEmpty

The .Net framework offers a static method in the string class: String.IsNullOrEmpty.

Syntax Example:
String^ s;
  
//s = ""; //Uncomment to test 2nd case.
  
if (String::IsNullOrEmpty(s))
{
  MessageBox::Show("empty string");
}
Access VBA:   Len(s&vbNullString)

In Access VBA, you have to add an empty string to the value being compared in order to get consistent results. For example, add &"" to your string varilable or it's code equivalent &vbNullString. Then compare to an empty string or verify it's length to 0 with Len.

Syntax Example:

All these will work for variables unassigned, set to "", or set to Null:

If s&"" = "" Then
  MsgBox ("Quotes with &'' say null is empty")
End If
 
If Len(s&"") = 0 Then
  MsgBox ("Len with &'' says null is empty")
End If
 
If Len(s&vbNullString) = 0 Then
  MsgBox ("Using vbNullString also works!")
End If




Logical Operators

[Other Languages] 

Languages Focus

Logical operators perform conditional and, or, and not operations. Some languages support both binary logical operators that link two and unary logical operators negate (make opposite) the truth value of its argument. Finally, some languages short circuit logic. For example, with this or that, if this is an expression returning true, then that is never executed.

C++/CLI: 

Same as C++ and Java. C# logical operators:

& and, as in this and that No Short Circuit
&& and, as in this and that short circuits
| or, as in this or that No Short Circuit
|| or, as in this or that short circuits
! Not, as in Not This
^ either or, as in this or that but not both

Syntax Example:
//Given expressions a, b, c, and d:
if !((a && b) && (c || d)) {
  //Do something.
}
Access VBA:   and, or, not

Same as VB. Access VBA logical operators:

and and, as in this and that
or or, as in this or that
Not Not, as in Not This

Access VBA never short circuits. Given the expression this or that as well as this and that, if this evaluates to false, then that is still executed.

Syntax Example:
'Given expressions a, b, c, and d:
If Not (a and b) and (c or d) Then
  'Do something.
End If




String Concatenation

[Other Languages] 
C++/CLI:  "String Concatenation" +

C++/CLI performs implicit casting of numbers to strings. To concatenate two strings, a string to an integer, or a string to a floating point number, use the + operator. For example, to convert a floating point number to a string just concatenate an empty string to the number as in "" + 3.2.

Alternatively, you can use the System.Text.StringBuilder class which frequently but not always provides faster code.

Syntax Example:  
//Implicit casting of numbers.
//
//This fails:
//MessageBox::Show(3.3);
//
//This works:
MessageBox::Show("" + 3.3);
Access VBA:  "String Concatenation" & or +

Although you can use either a & or a + to concatenate values, my preference is to use a + because more languages use it. However, if you use & then some type conversions are done for you. If you use + you will sometimes have to cast a value to concatenate it. For example, you will have to use CStr to cast a number to a string if you use the + operator as a concatenation operator.

Syntax Example:
Dim FirstName As String
Dim LastName As String
 
FirstName = "Mike"
LastName = "Prestwood"
 
MsgBox "Full name: " & FirstName & " " & LastName
 
MsgBox "2+2=" + CStr(2+2)




Unary Operators

[Other Languages] 

General Info: Unary Operator

An operation with only one operand (a single input). Common unary operators include + plus, - minus, and bitwise not. Some operators can function as both unary and binary operators. For example, + and - operators can serve as either.

Languages Focus

What unary operators are supported in additoin to the standard plus, minus, and bitwise not.

[Not specified yet. Coming...]
Access VBA: 

An operation with only one operand (a single input) such as +, -, and Not.





 
Commands
 

Common commands (procedures and functions). A function returns a value. Optionally, it may also perform an action prior to returning a value. A procedure does not return a value or it returns void or null.

Left of String

[Other Languages] 
[Not specified yet. Coming...]
Access VBA:   Left
Syntax Example:
Dim LeftString As String
LeftString = Left("Prestwood", 3)
MsgBox LeftString




 
OOP Basics
 

Some languages support object-based concepts such as Paradox, Access, and VB Classic. Other languages have OO extensions and fully support object orientation in a hybrid fashion (such as C++ and Dephi for Win32). Finally, some lanages such as C#, VB.Net, Prism, and Java are entirely written in OO. Meaning, every line of code written must occur within a class).

Base Class

[Other Languages] 

Languages Focus

When you create a class, it is either a base class or inherits from another class. Some languages require all classes to inherit from a common base class and some do not.

C++/CLI:   System::Object

In C++/CLI, the Object keyword is an alias for the base System::Object class and is the single base class all classes ultimately inherit from.

More Info / Comment
Access VBA:   Not Supported




Member Method

[Other Languages] 

Also known as a Class Method.

A code routine that belongs to the class or an object instance (an instance of the class). Methods that belong to the class are called class methods or static methods. Methods that belong to an object instance are called instance methods, or simply methods.

When a method returns a value, it is a function method. When no value is returned (or void), it is a procedure method.

Methods frequently use method parameters to transfer data. When one object instance calls another object instance using a method with parameters, you call that messaging.

[Not specified yet. Coming...]
Access VBA:   Sub, Function

Access VBA uses the keywords sub and function. A sub does not return a value and a function does. Many programmers like to use the optional call keyword when calling a sub to indicate the call is to a procedure.

More Info / Comment




 
OOP Details
 

More object oriented (OO) stuff.

Class Helper

[Other Languages] 

A. In Dephi, class helpers allow you to extend a class without using inheritance. With a class helper, you do not have to create and use a new class descending from a class but instead you enhance the class directly and continue using it as you always have (even just with the DCU).

B. In general terms, developers sometimes use the term to refer to any class that helps out another class.

C++/CLI:  "Class Helpers" Not Supported

However, developers sometimes use the term "class helper" to refer to code that helps out a class. Not truly the meaning we are using here, but you should be aware of the term's general usage.

Access VBA:  "Class Helpers" Not Supported




Code Contract

[Other Languages] 

A.k.a. Class Contract and Design by Contracts.

A contract with a method that must be true upon calling (pre) or exiting (post). A pre-condition contract must be true when the method is called. A post-condition contract must be true when exiting. If either are not true, an error is raised. For example, you can use code contracts to check for the validity of input parameters, and results

An invariant is also a code contract which validates the state of the object required by the method.

C++/CLI:  "Code Contracts" Not Supported
Access VBA:  "Code Contracts" Not Supported




Constructor

[Other Languages] 

General Info: Class Constructor

Constructors are called when you instantiate an object from a class. This is where you can initialize variables and put code you wish executed each time the class is created. When you initially set the member fields and properties of an object, you are initializing the state of the object. The state of an object is the values of all it's member fields and properties at a given time.

Languages Focus

What is the syntax? Can you overload constructors? Is a special method name reserved for constructors?

[Not specified yet. Coming...]
Access VBA:  "Constructors" Class_Initialize

When an object instance is created from a class, Access VBA calls a special parameter-less sub named Class_Initialize. Since you cannot specify parameters for this sub, you also cannot overload it.

When a class is destroyed, Access VBA calls a special sub called Class_Terminate.

More Info / Comment  




Destructor

[Other Languages] 

General Info: Class Destructor

A special class method called when an object instance of a class is destroyed. With some languages they are called when the object instance goes out of scope, with some languages you specifically have to call the destructor in code to destroy the object, and others use a garbage collector to dispose of object instances at specific times.

Desctructors are commonly used to free the object instance but with languages that have a garbage collector object instances are disposed of when appropriate. Either way, destructors or their equivalent are commonly used to free up resources allocated in the class constructor.

Languages Focus

Are object instances freed with a garbage collector? Or, do you have to destroy object instances.

C++/CLI:  "Finalizer" ~ClassName

Unlike standard C++, C++/CLI uses the .Net garbage collector to free managed object instances. Prism does not have nor need a true destructor.

In .Net, a finalizer is used to free non-managed objects such as a file or network resource. Because you don't know when the garbage collector will call your finalizer, Microsoft recommends you implement the IDisposable interface for non-managed resources and call it's Dispose() method at the appropriate time.

More Info / Comment
Access VBA: 

When an object instance is destroyed, Access VBA calls a special parameter-less sub named Class_Terminate. For example, when the variable falls out of scope. Since you cannot specify parameters for this sub, you also cannot overload it.

To explicitly destroy an object, use Set YourClass = nothing.

When an object instance is created from a class, Access VBA calls a special sub called Class_Initialize.

More Info / Comment  




Inheritance-Multiple

[Other Languages] 
[Not specified yet. Coming...]
Access VBA:   Not Supported




Interface

[Other Languages] 

An element of coding where you define a common set of properties and methods for use with the design of two or more classes.

Both interfaces and abstract classes are types of abstraction. With interfaces, like abstract classes, you cannot provide any implementation. However, unlike abstract classes, interfaces are not based on inheritance. You can apply an Interface to any class in your class tree. In a real sense, interfaces are a technique for designing horizontally in a class hierarchy (as opposed to inheritance where you design vertically). Using interfaces in your class design allows your system to evolve without breaking existing code.

[Not specified yet. Coming...]
Access VBA:  "Interfaces"

Same as in VB6. Access VBA has limited support for interfaces. You can create an interface of abstract methods and properties and then implement them in one or more descendant classes. It's a single level implementation though (you cannot inherit beyond that). The parent interface class is a pure abstract class (all methods and properites are abstract, you cannot implement any of them in the parent class).

In the single level descendant class, you have to implement all methods and properties and you cannot add any. Your first line of code is Implements InterfaceName.

More Info / Comment




Partial Class

[Other Languages] 

A partial class, or partial type, is a class that can be split into two or more source code files and/or two or more locations within the same source file. Each partial class is known as a class part or just a part. Logically, partial classes do not make any difference to the compiler. The compiler puts the class together at compile time and treats the final class or type as a single entity exactly the same as if all the source code was in a single location.

Languages Focus

For languages that have implemented partial classes, you need to know usage details and restrictions. Can you split a class into two or more files? Can you split a class within a source code file into two or more locations? What are the details of inheritance? Does it apply to interfaces as well?

C++/CLI:  "Partial Classes" Not Supported

C++/CLI does not yet support partial classes. My assumption is that it will soon because it is a .Net language�but only time will tell.

Access VBA:  "Partial Classes" Not Supported




Prevent Derivation

[Other Languages] 

Languages Focus

How do you prevent another class from inheriting and/or prevent a class from overriding a member.

C++/CLI:   sealed
Access VBA:   Not Supported




Static Member

[Other Languages] 

General Info: Static Class / Static Member

A static member is a member you can have access to without instantiating the class into an object. For example, you can read and write static properties and call static methods without ever creating the class. Static members are also called class members (class methods, class properties, etc.) since they belong to the class and not to a specific object. A static class is a class that contains only static members. In the UML, these classes are described as utility classes.

Languages Focus

Languages that support static members usually at least support static member fields (the data). Some languages also support static methods, properties, etc. in which case the class member is held in memory at one location and shared with all objects. Finally, some languages support static classes which usually means the compiler will make sure a static class contains only static members.

[Not specified yet. Coming...]
Access VBA:  "Static Members" Not Supported




Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]