Implementing Desktop Applications with Visual Basic 6.0
Supporting the Application
When you add licensing
support to a control component, a license key is compiled into
it. Licensing is only good for ActiveX controls.
To add Licensing support
Go to Project
Select the General
Check Require License
During the setup of your
control on a client machine, the key is added to the registry.
If a client has a copy of your control, but not the registry
key, the component cannot create instances of itself in the
A user can run a compiled
application without having the control component’s license key
in the registry.
Every class has at least 1
interface called the default interface. The name of the class
is preceded by an underscore, signifying that the name is
hidden in the type library.
If the class raises events,
it uses the interface: IConnectionPointContainer
GUIDs are automatically
generated by VB that identifies your type library in the
registry. A GUID is generated for each public class (called
CLSID) and for each Interface ID (called IID). The CLSID and
IID are used for version compatibility.
If Project Compatibility or
No Compatibility is selected in Project Properties, a new
CLSID and IID is generated every time you compile. Binary
Compatibility does not create new GUIDs
The Implements statement
allows you to add multiple interfaces to class
When coding use "No
Compatibility" to make a clean break.
Be sure to change the
name of the component so the incompatible version won’t
over-write earlier versions.
Change the name of the
project, so the new component will have a different type
Use "Project Compatibility"
to simplify development, use "Binary Compatibility" for new
versions of existing components.
Use the registry to store
information like: window positions and files used. VB provides
a standard registry location for applications:
HKEY_CURRENT_USER\Software\VB and VBA Program Settings\appname\section\key
VB uses 4
statements\functions to manipulate the registry
Saves or creates registry
Returns an array containing
multiply reg. entries
Save the Object
Copy it to the
appropriate subdirectory of the VB Template Directory
Adding Controls to a Project
From Project menu choose
Select the checkbox to
the left of the control name
ActiveX controls usually
have the extension .ocx. Each control is accompanied by a file
with an .oca ext. This file stores type library
To add a reference to a
From Project menu choose
Select the checkbox next
to the reference you want to add
A resource file allows you
to control all of the region-specific text and bitmaps for an
application.To add a resource
From Project Menu choose
Select an existing
resource file(.res) and choose open
You can add new properties,
methods, and events without breaking applications compiled
using earlier versions; however you cannot remove members from
the interface, or change the arguments of the
You can retain a property
for backward compatibility, but stop mentioning it in your
Help file, and mark it as hidden using the Procedure
Attributes dialog box.
In VSS, files can be shared
among multiple projects. Changes made to the file are
automatically seen by all projects.
Branching is the process of
taking a file in 2 directions. After you branch a file, the
Links tab does not show the link that has been broken. Instead
use the Paths tab to view the branch history of the
To get the latest version
of a file, click Get Latest Version on the VSS menu. To get an
older version, click Get in the History of File or History of
Project. You must have read access rights to do this.
There are 4 outcomes to Get
If the file you are
retrieving is not in your working folder, VSS just gets the
When the file in your
working folder is identical to the one your are getting, VSS
does not retrieve or modify the file in any way.
When the file is in your
working folder and is read only, VSS replaces your local
copy with the new one.
When your existing file
is not Read-only, VSS assumes you have the file checked out
and doesn’t replace the file.
The administrator only has
2 levels of access rights to choose from for adding new uses
Read-only: The use can
see everything, but change nothing.
Read-write: The use can
see and change anything in the VSS DB.
All security is set from
inside the VSS Administrator. To protect the administrator
Assign a password using
Change Password command.
Protect the VSS folder
using the ACL of the operating system.
Deriving the Physical
Use the Property GET to get
the value of property from an object:
Example: Property Get
Created() as Date
Class modules have 2
events: Initialize and Terminate
If myObj is declared as
New, it will be created the moment one of its properties or
methods is invoked.
Using the End command or
End Button halts execution of code, without firing the
ActiveX components interact
through a client server relationship.
If an ActiveX component is
part of a .exe, it is an out-of-process-server.
If it is a .dll it is an
There are 3 kinds of
components that can be created:
runs in its own
can have asynchronous
untrapped errors won’t
cause the calling application to crash
16 and 32bit apps
use the resources of
Network overhead will
exact a toll
Make Tab of Project
Major – Major Release
number of the project 0 – 9999
Minor – Minor release number of the
project 0 – 9999
Revision – Revision number of the project 0 –
Title - Name of the
Icon for the application
Type – Set values for
company name, description, legal copyright, legal trademarks,
product name, and comments.
Command Line Arguments
Allows you enter the
arguments that VB sends to an app only when you choose start
from the run menu.
Allows you to enter the
constant declarations used for conditional
File DSN. Connection
information is stored as a file that can be read by any
Machine DSN. Connection
information is stored in the Registry.
If you are developing an
app in C++ or J++ you can use a file or machine DSN.
If you use the Setup
Wizard, you must setup a machine DSN, by modifying the
To test component download
on a development machine:
Right-click the control
(in either the Winnt or Windows Dir) and select REMOVE
Run regsvr32 /u
To test support file
installation, first uninstall support files by:
Right-click the file and
select REMOVE or
Use the following
command line: for %f in (*.ocx *.dll) do regsvr32 /u /s
To reregister support
files, run: for %f in (*.ocx *.dll) do regsvr32 /s
To debug an out-of-process
Set breakpoints and
watches in the class module.
Run the component
project by pressing CTRL-F5 or clicking START WITH FULL
Start a second instance
of VB, set any break points.
Create a test
application that calls the component.
Run the application. If
the focus is not set to the component project, click the
SWITCH 0TO button.
Close the test project
before stopping the component project.
The only accurate way to
test shutdown behavior (Terminate Event) is with a fully
StartMode is a read-only
property of the App object.
Package and Deployment
There are 3 ways to start
the Package and Deployment Wizard.
Run it from VB as an
Add-in. Use the Add-in manager, from the Add-ins menu if the
Package and Deployment wizard is not a pick off the
Run it as a stand-alone
component. You will need to select the project you want to
Run it in silent mode
from a command prompt. The name of the .exe is pdcmdln.exe.
It has these arguments:
packagingscript where packagingscript is the
name of a previously saved packaging script.
where deploymentscript is the name of the
previously saved deployment script.
where path is the location into which the
wizard should store all the output.
C:\Project1\Project1.vbp /p "Internet Package" /d Deployment1
/l "C:\Project1\Silent Mode.log"
There are 3 Options
Package Option. Packages
all of your project files into a .cab file, and sometimes
creates a setup program to install the .cab file.
Deploy Option. Delivers
your packaged applications to floppies or a network share
(standard package), or deliver to a web site (Internet
Manage Scripts. Lets you
view and manage scripts that are saved from previous
packaging and deployment sessions. You can use scripts to
deploy the app in silent mode.
The setup package is called
To create features not
supplied by the setup, modify the setup toolkit
There are 5 types of
Internet packages from VB
ActiveX controls (.ocx
files) displayed on a web page.
ActiveX .exe or .dll
designed to run on the client or webserver
ActiveX documents are
displayed in place of a web page.
Internet Packages contain
Primary .cab file that
is used as the setup program. It contains: the .exe or .dll
for the app, an .ocx for controls, a .inf for referencing
Support files, which can
include, HTML help, graphics, and other files needed for
Secondary .cab files,
which can contain: VB run time dll, individual ActiveX
controls, data access objects. Use secondary .cabs to make
sure the user has the latest components on their
5 steps to using the
Packaging and Deployment Wizard
Determine the package
you want to create: Standard or Internet
Determine the files you
need to distribute. Both project files and dependant files.
Dependent file information is stored in vb6dep.ini file or
various .dep files.
Determine where you want
to install the files on the persons machine
The setup program copies
the application removal utility: st6unst.exe. An uninstall log
file called st6unst.log is generated.
The log file contains
Files installed and
Registry entries created
Links and start menu
entries in Windows95 or Winnt40 and later.
Self- registered .dll,
.exe, or .ocx files.
Shared files are set by
adding the files to the Shared Files screen of the Package and
Deployment Wizard or by indicating the installation location
for the file as a shared directory.
Situations that will make
the application removal utility fail.
The end user copied
The end user deleted
files rather than using the application-removal
Another setup program,
not compliant with Win95, installs the same shared
A shared file is
installed into a different directory.
The end user installs
the same VB app into 2 different directories.
The end user deletes
The setup.lst file contains
all the files that must be installed on the user’s machine for
your application. There are 5 sections to this
Lists the core information
about the installation, it is divided into
Setup Title – The title
to show in the dialog box that appears while the setup.exe
is coping files to your system.
SetupText – The text to
show in the dialog box.
CabFile – The name of
the primary .cab file (or the only .cab file).
Spawn – The name of the
application to run after setup.exe is done, probably
TmpDir – Temporary dir
used during installation.
Uninstall – Name of the
application to use as the uninstall, probably
Lists all files required by
the main installation files, like the msvbvm60.dll. The setup
installs these files prior to installing and launching the
main installation program.
The setup program installs
these files, after it installs the core files listed in the
bootstrap file's section. These files include your .exe, data,
text, and dependancies.
A list of information used
by other parts of the installation process. It is divided up
Title – The name of the
application as it will appear in the splash screen during
DefaultDir – Default
ForceUseDefDir – If set
to 1, the app is automatically installed in DefaultDir.
AppToUninstal – The name
you wish to see as your app in the Add\Remove programs
utility in Control Panel.
AppExe – The name of the
Contains info about the
Start menu program groups.
The BootStrap Files and
Setup1 Files must use the following format:
Filex – A keyword, where X
is the file number, starting with 1 and going up.
File – The name of the
file, as it will appear on the user's computer.
Install – The name of the
file found on the distribution media.
Path – The directory to
which the file should be installed.
Register – A registry key
that indicates how the file is included in the
Shared – Specifies that the
file should be installed as shared.
Date – The last date the
file was modified.
Size – Size of the file,
used to calculate setup disk space.
Version – Optional internal
version number of the file.
The RESUME statement
returns control to the statement at which the error occurred,
and attempts to re-execute that statement.
RESUME NEXT causes the
function to continue execution at the statement following the
one at which the error occurred.
Err.Raise generates a
Syntax: Err.Raise number,
source, description, helpfile,helpcontext
All arguments are optional
except for number.
The default property of the
error object is Number.
The Err object’s properties
are reset to zero or zero length strings after an Exit Sub,
Exit Function, Exit Property, or Resume Next
There are 3 error trapping
options: (set by the General Tab of the Options Dialog
Break in Class
Execution will not stop
if you have an error handler written.
Execution only stops on
unhandled errors in a class module.
This is the default VB
If no classes are
written, this is the same as Break on Unhandled
Break on Unhandled
Only breaks on errors
without error handlers.
Break on All
Any error that occurs will
cause the project to enter break mode.
Turn off error handling by
using ON ERROR GOTO 0 or exiting the procedure with an error
If an error occurs in a
procedure that doesn’t have an enabled error handler, VB
searches backward through the procedures on the calls list,
back to the initial calls event. If it doesn’t encounter an
error handler, it presents a default unexpected error message
and halts execution. If VB finds an error-handling routine,
execution continues in that routine as if the error had
occurred in the same procedure that contains the error
Use Err.clear to explicitly
clear the Err object after handling an error.
There are 3 debugging
windows: Immediate, Watch and Locals
Shows information from
debug statements in your code, or that you request by typing
into the window.
Use to find the values of
procedures, expressions, or assign new values to variables or
?intX (will display the
value of intX, the same as Print intX)
X = Quadratic(2, 8, 8)
DisplayGraph 50, Arr1
Form_MouseDown 1, 0, 100,
Statements can only be
evaluated if they can be expressed on a single line. Use
colons to separate the statements that make up a control
Use Debug.Print inside of
code to display expressions in the immediate
Use a semicolon or comma to
separate 1 item from the next. A semicolon prints 1 item after
another. A comma moves the item to the next tab
By default the print method
prints the text and moves to the next line.
Use the STOP statement to
put VB in break mode and display the Immediate window. Remove
all STOP statements before you compile, or they will cause the
app to end. VB treats the STOP statement as it treats END, and
terminates execution without any QueryUnload or Unload
Use the ASSERT statement
rather than STOP. ASSERT is automatically removed when the
application is compiled. ASSERT conditionally suspends
execution at the line on which the method occurs.
It is possible to display
values for objects, regardless of scope, if the fully
qualified object name is provided.
Shows watch expressions are
expressions whose values you decide to monitor as the code
runs. A break expression is a watch expression that will cause
VB to enter bread mode when a certain condition becomes
Only displays values that
are in context.
Drag a variable into the
watch window or immediate window to see its value.
If the context of the
expression isn’t in scope, the current value isn’t
To add a watch expression,
use the Add Watch Dialog Box. Set the following
Expression Box – Enter the
expression the watch expression evaluates. Either a variable,
property, function call or any valid expression.
Context Option Group – Sets
the scope of the watch by Procedure and or module. Can also
set it to All Procedures and All Modules.
Watch Type Group – Set with
one of three values: Watch Expression, Break when Value is
true, Break when value changes.
To edit or delete a watch,
double click the expression in the watch window.
The values of any variables
within the scope of the current procedure.
To debug in process
components, load 2 or more projects into a project
When you set a breakpoint,
VB halts just before executing that line of code.
lets you selectively compile certain parts of the program. To
conditionally compile a part of code, enclose it between #if…
then and #endif statements, using a Boolean test.
There are 3 ways to declare
conditional compilation constants
Setting Constants on a
Example: vb6.exe /make
MyProj.vbp /d conFrenchVersion=–1:conANSI=0
Use #const statement in
The call stack displays all
functions on the stack that have started, but not completed.
It places the earliest active procedure call at the
The call stack is only
visible in break mode.
Because a project group can
contain multiple projects, VB needs to know which project to
execute first. To specify a project, right-click the project
and select SET AS START UP.
P-code is an intermediate
step between the high-level instructions in VB and the low
level native-code of the computer’s processor.
Native Code can be debugged
using C++ tools.
Native code takes advantage
of the processor, however, you still need the MSVBVB60.DLL.
Native code provides the following options
Assume No Aliasing –
Tells the computer to apply optimization such as storing
variables I registers
Create Symbolic Debug
Info – Allows debugging with VC++5.0 or compatible
Favor Pentium Pro –
Optimizes code for the Pentium Pro.
No Optimization –
Disables all optimizations.
Optimize for Fast Code –
Favor code speed over size.
Optimize for Small Code
– Favor code size over speed.
Remove Array Bounds
Checks – Disables array bounds checking.
Remove Floating Point
Error – Disables floating-point error checking.
Remove Integer Overflow
Checks – Disables overflow checking.
Remove Safe Pentium FDIV
Checks – Disables checking for safe Pentium processor
floating point division.
Logs an event in the
application’s log target. On NT, the method writes to the NT
Event Log. On Win95 the method writes to the file specified in
the LogPath property. By default the file name is
User Objects, their
methods, their properties
Returns the control that
has the focus. Each form can have an active control,
regardless of whether or not the form is active.
Add Method (Tabs
Adds a Tab object to the
Tabs collection in a TabStrip control.
Returns a reference to a
newly inserted Tab Object
Index - optional - an int
specifying the position where you want to insert the
Key - optional - a unique
string that identifies the Tab.
Caption - optional - the
string that appears on the tab.
Image - optional - the
index of an image in an associated ImageList
AddItem Method(ListBox or
Adds an items to a Listbox
A ListBox or ComboBox that
is bound to a Data control doesn’t support the AddItem
Item – required – a string
expression specifying the item to add to the
Index – optional – Int
specifying the position within the object where the new item
or row is placed.
This Event occurs when the
user clicks a Button object in a ToolBar
Occurs when the user
presses and releases a mouse button over an object. Also
occurs when the value of a control is changed.
To distinguish between
left, right, and middle mouse buttons, use the MouseDown and
You can trigger a Click
Event in code by:
Setting a CommandButton
controls Value property to TRUE
Setting an OptionButon
control’s VALUE property to TRUE
Changing a CheckBox
control’s Value property setting.
A control array is a group
of controls that share the same name and type. The maximum
index in a control array is 32767. Adding controls using a
control array uses fewer resources than simply adding new
controls. To add or remove a control in a control array at run
time use Load and Unload statements.
Settings are copied from
the lowest existing element in the array.
You cannot Unload controls
created at design time.
Syntax: Load object(index%)
Object – name of the
control to add.
Index% - The index value in
Declares variables and
allocates storage space.
If you do not specify a
data type or object type, the variable is Variant by
A numeric variable is
initialized to 0.
A string is initialized to
a zero-length string.
A fixed length string is
filled with spaces.
Variants are initialized to
Occurs when a Drag-and-Drop
operation is in progress
If the source control is
dropped on the object, that object receives a DragDrop
Syntax: Private Sub
object_DragOver([index As Integer,]source
As Control, x As Single, y As Single,
state As Integer)
Index – Used to reference
an object in a control array.
Source – The control being
X,Y – Position of the mouse
State – The transition
state of the control being dragged. One of: Enter, Leave,
Caption property: the text
that is shown in the form’s title bar.
Icon property: the icon
that is displayed when the form is minimized.
Left property: the location
in relation to the left side of the screen.
Top property: the location
in relation to the top of the screen.
Name property: sets the
name used in the code.
Resize event: triggered by
resizing the form by using the mouse or by code.
Activate event: triggered
by the form becoming the active form.
Deactivate event: triggered
when another form or application becomes active.
Show method: the same as
setting the form’s Visible property to true.
A form goes through 4 states
Created, but not loaded.
This is the only state all forms pass through.
Marked by the Initialize
event. The form exists as an object, but has no
Example: Set frm = New
Loaded, but not shown.
Marked by the Load event.
Shown - The form becomes
Member and resources
completely reclaimed. Marked by the terminate event.
Example: Set frm =
Execute a hyperlink jump
back in the history list.
The HelpFile property of
the App object is used to specify the name of the help file.
Must be .hlp or .chm.
The Err Object also has a
The HelpContextID property
is used to link a user interface element to a related topic in
a help file.
To assign a HelpContextID:
Select the control or
HelpContextID in the properties window and enter a Long
Index Property (control
Returns or sets the number
that uniquely identifies a control in a control array.
The KeyPress event can
process a double-bye character code as one event.
Example: Private Sub
Form_KeyPress(keyascii as Integer)
Convert the keyascii
argument into a character by using Chr(keyascii)
Use Asc(char) to convert
back to keyascii.
KeyPress interprets A and a
KeyDown and KeyUp view A
and a as the same.
If KeyPreview is set to
True, the form receives the event before the controls on the
form receive the event.
If no item is selected, the
ListIndex property value is –1. The first item in the list is
0. The value of ListCount property is always one more than the
largest ListIndex value.
Use AddItem or RemoveItem
to add or remove items.
There are 4 different views
Icon – Allows the user
to drag and drop icons.
Small Icon – Allows more
ListItem objects to be viewed.
List – Presents a sorted
list of items.
Report – Presents a
sorted view with SubItems allowing extra information to be
A method executes a
hyperlink jump to a specified target. If the container
supports OLE hyperlinking, it will jump to the location, else
the registered application that supports hyperlinking will
handle the request.
Any menu that has at least
one menu item can be displayed at run time as a pop-up
[object.]PopupMenu menuname [, flags
[,x [, y [, boldcommand ]]]]
Only 1 Menu can be
displayed at a time.
Flags – vbPopupMenuLeftAlign. – The specified x location defines the
left edge of the popUp menu.
the pop-up menu is centered around the specified x
VbPopupMenuRightAlign – The
specified x location defines the right edge of the pop-up
Set the visible property to
True to show the control at the start of an operation, and
visible=false at the end of an operation.
This statement is used at
Module level to declare variables and allocate storage space.
A PUBLIC statement cannot be used in a class module to declare
a fixed length string.
The QueryUnload Event
occurs before a Form or Application closes. The event is used
to make sure there are no unfinished tasks in the forms
included in an application before the Application closes. If
you use the End statement of the End button, this event does
Returns a value indicating
whether the elements of a control are automatically sorted
A panels collection
contains a collection of Panel objects. The collection is a
The Panels property returns
a reference to a Panels collection.
The PanelDblClick event
occurs when someone double-clicks the panel.
The Style property sets the
style of a StatusBar control’s Panel object. The StatusBar can
toggle between two modes: Normal and Simple.
Returns or sets the tab
order of most objects within their parent form. If you delete
an object, you can Undo the delete; however, the TabIndex
property is not restored, it is reset to the end of the tab
order when you use Undo.
Returns or sets a ToolTip.
Syntax: object.Tooltip [=
For a Toolbar and TabStip
control, you must set the ShowTips property to True to display
The Add method adds a Node
object to a Treeview control’s Nodes collection. The
collection is 1-Based.
object.Add(relative, relationship, key, text, image,
selectedimage) Returns a reference to a newly created node
tvwMytree.nodes.add "7 node", tvwChild, "11 node"
Relative – Optional -the
index number or key of a pre-existing node, position is
determined by relationship.
Relationship – Optional
-Specifies relative placement of the node object.
TvwFirst – The node is
placed before all other nodes, at the same level as the node
TvwLast – The node is
placed last, as the same level as the node in
Tvwnext – The node is
placed after the relative node.
TvwPrevious – The node is
placed before the relative node.
TvwChild – The node become
a child of the relative node.
Key - Optional - A unique
string though out the collection.
Text – Required - String
that appears in the node.
Image – Optional – Index of
an image in the ImageList control
Selectedimage – optional –
the index of the image in the ImageList control when the node
When node is added, it is
assigned an index number.
ObjTreeView.Nodes.Item(index) refers to a node object
in a TreeView. Index is an int or a string that uniquely
identifies a member of a nodes collection. The int is a value
of the Index property, the string is a value of the Key
Returns the class name as a
Can only be used in
If…Then…. Else statements.
Syntax: If TypeOf MyControl
is Checkbox then….
The Unload event is fired
after the QueryUnload event. When a form is unloaded, all
controls placed on the form at run time are no longer
accessible. Controls placed on the form at design time remain
intact. All changes to the form properties are also lost.
Accessing any controls on the form causes it to be
Setting the WhatsThisHelp
property of a form to True enables What’s This Help, however,
context sensitive help for the form is disabled. Must be
contained in a Cshelp.text file that is compiled into the .chm
Set the following
properties to add a what’s This button to the title bar of the
BorderStyle 1-Fixed Single
or 2 – Sizable
Passing by reference is
default in VB.
Use the Optional keyword in
an arguments list to specify an optional argument. When
optional arguments are not provided, the argument is actually
assigned as a variant with the value of Empty.
The ParamArray keyword
allows you to specify that a procedure will accept an
arbitrary number of arguments.
You can use the syntax
MyArgument:="Some Value" to pass values into a
You can make an ActiveX
control without a user interface, but it should normally be
visible. If you need an invisible control, consider writing an
automation server with event support. A timer control is an
example of an invisible ActiveX control.
There are 2 different views
in the code editor. One version allows you to view a single
procedure, the other version allows you to view all the
Bookmarks can be used to
mark lines of code in the code editor.
Creating and Managing COM
When a method is declared
with the Friend keyword, it’s visible to other objects in your
component, but is not added to the type library or the public
Example: Private msoc as
Friend Property Get
Socket() as Socket
Set Socket =
Is used to provide thread
safety and works by giving each apartment its own copy of
You cannot us global data
to communicate between objects on different threads. However,
objects in different apartments can communicate if a client
passes references to them.
All components in VB use
the apartment model.
A multithreaded in-process
component has no threads of it’s own, they each belong to the
out-of-process component may have a thread pool with a fixed
number of threads.
For DLLs and ActiveX
controls, select either Apartment threaded or single
For ActiveX EXEs, specify
that each new object is created on a new thread, or a fixed
To Set Unattended Execution
(allow components to run without operator
On General Tab, check
The Development environment
doesn’t support multithreaded debugging.
MDI Forms are not allowed
in apartment – threaded projects.
Friend Properties and
Methods can only be called by objects on the same
ActiveX Docs in ActiveX EXE
projects will not be apartment-model thread-safe unless you
select Thread Per Object or Thread Pool.
When a thread shows a
vbModal form, the form is only modal to the code and forms on
It is possible to trick VB
into using a single-threaded control in an apartment-threaded
project by manually editing the .vbp file. DO NOT DO
A collection is an object
that contains a set number of related objects.
For only a client to create
an object set Instancing to PublicNotCreatable.
To make objects externally
creatable, set the Instancing property to MultiUse.
Objects that are creatable
and dependent should be designed to require no initialization
beyond their Initialize events.
DLLs run in the same
process as your Application.
ActiveX EXEs usually run in
an out-of-process server.
Here are some
Code Component Either
In-process or Out-of-process
ActiveX document Either
in-process or out-of-process
To declare a new object
use: Dim myObj as New Worksheet.
VB will automatically
create the new object the first time you use the
Use: Set myObj =
Create("progID",["servername"]) to assign an object reference
to a new variable
Use: Set myObj =
GetObject([pathname][,progID]) to assign an object reference
to an existing object
Use the Add Annotation
Dialog box to enter textual annotations or comments to a
Create a form that will
contain the About information.
Create a Sub that will
show the box, vbModal, and unload it.
On the Tools menu, click
Procedure Attributes, in the Name box, click the drop down
and select it.
In the Procedure ID,
select AboutBox to give the procedure the correct
Compiling a component
automatically registers it as an Add In. To register a DLL
(in-process component) use regsvr32.exe. To register an
out-of-process component add the /regserver parameter to the
.EXEs file’s command line.
Optimize Objects by
Use Set and With…End
An ActiveX doc is composed
of a UserDoc, Code, Code Module, and Controls. The .dob file
contains the source code and property values. The .dox
contains the graphical elements that cannot be stored as plain
text. .dox are equivalent to .frx
A compiled ActiveX doc will
be an .EXE or a .DLL and will have an accompanying .vdb, which
IE will open. The .vbd will be placed in the same directory as
the .exe or .dll. Use the NavigateTo method to move to
different ActiveX docs.
Example: Private Sub
The properties and methods
of a class make up its default interface. The following names
cannot be used a property or method names:
QueryInterface, AddRef, Release, GetTypeInfoCount,
GetTypeInfo, GetIDsOfNames, and Invoke.
Data hiding is the ability
of a project to protect part of an objects data.
Property procedures allow
an object to protect and validate its own data.
To Test a component you
need to create a client application. Test for both
functionality and error cases. Create a generic application
that tests each element of the objects interface.
The test project must be an
EXE. Usually make your project a standard EXE, however, to
test call backs, use an ActiveX EXE, so it can include public
classes that implement call back methods.
ActiveX Documents cannot be
debugged without a browser.
Use the Procedure
Attributes dialog box to enter description strings for your
properties, methods, events, and to provide lines to topics in
your help file. Users can view these descriptions using the
Object Browsers. The Object Browser can also be used to enter
To enter these descriptions
using the Procedure Attributes Box
Open a code window of
On the tools menu, click
Select a property name,
method, or event in the Name box.
Enter the HelpContextID.
You cannot supply help
topics or browser strings for enumerations.
Determines whether your
class is Private or available for other applications. It also
determines how other applications create instances of the
class. Instancing can have
Private – Other
applications aren’t allowed access to the type library. Only
for use within your own component.
Other applications can use objects of this class, only if
your component creates the objects first. Cannot use
CreateObject or New operators with this instance.
MultiUse – Allows other
applications to create objects from the class. One instance
can provide any number of objects.
GlobalMultiUse – Like
MultiUse, plus, properties and methods can be invoked if
they were global functions without explicitly creating an
instance of the class first.
SingleUse – Allows other
applications to create objects from the class, but every
object states a new instance of the component.
GlobalSingleUse – Like
GlobalMultiUse, except SingleUse instead.
Use the following table for
The Object Browser displays the
classes, properties, methods, events and constants available
from object libraries, and the procedures in your
By default the properties
of the UserControl object, and the constituent controls you
add to it, are not visible to the end user of the
To expose a property,
expose the property of the constituent control.
Example of the BackColor
property: Public Property Get BackColor() as
To Map properties to
multiple controls use a For Each loop and check the TypeOf
By Default, MTS does not have any users
mapped to the administrator role, that means, anyone with an
account can modify package configuration on the computer. By
default there are 2 roles, the Administrator Role, and a
Reader Role. Administrators can do anything, Readers cannot
install, create, change, or delete objects, shut down server
processes, or export packages. They can view all objects in
the MTS Explorer hierarchy.
Visual Component Manager
VCM handles publishing,
finding, and reusing components.
It is a single source to
organize, find, and insert components into your
Publishing means storing it
in a Visual Component Manger database, this can be MS Access
or SQL Server. This provides a single source for anything that
can be added to a MS Visual Studio project. In addition to
components, VCM can also store component libraries, templates,
models, and complete application frameworks.
Finding provides a flexible
keyword and search mechanism to help organize and
cross-reference components .
To reuse a component, click
Add to my project on the component’s shortcut
There are 2 parts to
Asynchronous processing: the first part is the responsibility
of the author, the second part is the responsibility of the
developer who uses the component.
The Author must
Define the tasks or
notifications to be performed.
Provide 1 or more
externally creatable classes to manage the tasks.
Provide a manager class
with methods that clients can call to initiate tasks or to
Declare the events that
clients must handle in order to receive
Write code to start the
task or the process or watching for interesting
Write code to raise the
event when the task is complete, or when occurrences are
The Developer must
Create a WithEvents
variable to contain a reference to the object that will
provide the notification events.
In the event procedures,
write the code to handle the notification events.
Write the code to
request an instance of the component’s manager class and
place the reference to it in the WithEvents variable.
Write code to call the
methods that initiate tasks or that request
A single event can be
handled by multiple clients.
Call Back Methods
The Developer must
Create a public class
that implements the interface defined by the component
In the call-back methods
the client will use, write the code to handle the
notifications. All the methods of an interface must
Write code to request an
instance of the manager class.
Write code to call the
methods that initiate tasks or request notifications.
Indexed Sequential Access
Method (ISAM) file applications commonly process each record
one by one, to the end of the file.
Properties, Events of ADO:
Can be thought of as an
Array of Rows.
The state property for a
Recordset executing an asynchronous method whether the state
is connecting, executing, or fetching, or
Called whenever a warning
occurs during a ConnectionEvent operation.
There are 2 families of
events: ConnectionEvent (Connection Object) and
RecordsetEvent(Recordset Events). Events called before an
operation usually have the naming convention WillEvent
. Events called after an operation concludes usually have
the naming convention EventComplete.
Execute Method (Connection
Executes a query, SQL
Statement, stored procedure, or provider-specific
For a row returning
recordset, a recordset object reference is returned. The
recordset is always a read-only and forward-only
If an error occurs in ADO,
error objects are placed in the Errors collection of the
Connection Object. The error object represents a specific
provider error, not an ADO error. The SQLState and NativeError
properties, of the Error Object provide information from the
SQL Data sources. Use the Clear Method to clear the Errors
ADO Data Control
The ADO Data Control is
used to create connections between data-bound control and data
4 Uses of the control
Connect to a local or
Open a table or SQL
Statement, or Stored Procedure
Pass data field values
to data-bound controls
Add\Update Records in
The control is inefficient
and requires 2 connections to the database for the first
control, and 1 connection for every control afterwards. To
connect to a data source, you will need to specify one of the
following: a connection string, a .UDL file, or a DSN.
The Recordset property sets
a recordset object defined by a Data control’s properties. The
type of Recordset is determined by the Type property. The
records of the recordset can be determined by moving to the
last record in the recordset and examining the RecordCount
property. The DataControl doesn’t support forward-only
The validate event of the
Data Control occurs before a different record becomes the
current record, before the UPDATE method, before a Delete,
Unload, or Close Operation.
Some other Events of the
ADO Data Control
WillMove On Recorset.open,
any record move, Recordset.Requery,
WillChangeField Before the
Value Property Changes
Recordset.Update, .Delete,.CancelUpdate,.UpdateBatch, .CancelBatch
InfoMessage When the data
provider returns a result.
Use Cursors only when
you need to.
Load the cursor
immediately by moving to the last row. This releases the
share locks taken when the cursor was built.
Use client-side cursors
Fetch a smaller result
Use multiple result
Submit multiple queries
asynchronously by using Microsoft Message Queue
Use the minimum
Use off-hours for bulk
The default cursor,
forward-only, can only move forward through the result set and
does not support scrolling. After data for the current row is
processed, the cursor releases the resources that were used to
hold the data. Forward-only cursors are dynamic because all
changes are detected as the current row is
4 ADO Cursors
4 Locking Options
using row values.
Read-only. Changes are
Updates are deferred until the batch update is finished.
Need keyset or static cursor.
The CursorLocation property
returns the location of the cursor engine. Can be adUseClient
or adUseServer. AdUseNone is solely for the sake of backward
To Create a Master/Detail
Create a parent/child
data environment command object.
Create a command object
the Data Environment.
Define its SQL
Add a child command by
right-click on the parent command in the Data Environment
designer, then select Add Child Command, from the popup
Define the SQL
Statements for the child command object.
Define the Parent-Child
relationship by clicking the properties of the child
command, select Relation tab, and define the relationship
between the Parent and Child Fields.
Drag the Command object
from the Data Environment designer to a blank form.
To Create a Data
Create a new standard.exe.
Add a Data
In the connection
properties, select the correct OLE DB provider and
Create a Command
Set the Command Name,
Connection, and DataSource.
Add a Data
In the Data Report
properties, set the DataSource and DataMember.
Right click the Data
Report designer, click Retrieve Structure.
From the Data
Environment, drag the fields you want on the report.
If there isn’t a form in
the project, add one.
Add a command button, to
the command_click sub, and add the syntax: reportname.show.