0% found this document useful (0 votes)
107 views

BasicVBA 03 VBAEditor

The VBA editor contains several windows for working with macros: 1. The Project Explorer shows all modules and forms in a project. 2. The Properties Window displays properties of selected objects. 3. The Code Window contains code for modules and forms. 4. The Locals Window shows active objects and their properties while debugging. The document provides an example of using these windows to step through a macro that creates a smartline in Microstation, with variable values updating in the Locals Window at each step.

Uploaded by

dynamicsamcom
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views

BasicVBA 03 VBAEditor

The VBA editor contains several windows for working with macros: 1. The Project Explorer shows all modules and forms in a project. 2. The Properties Window displays properties of selected objects. 3. The Code Window contains code for modules and forms. 4. The Locals Window shows active objects and their properties while debugging. The document provides an example of using these windows to step through a macro that creates a smartline in Microstation, with variable values updating in the Locals Window at each step.

Uploaded by

dynamicsamcom
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Basic MicroStation Visual Basic for Applications

Lesson 3: The VBA Editor

The next step is finding your way around the VBA Editor, and
understanding what each window does.

3 4
1 6

5
2

The layout may not be exactly the same on your screen; these windows
can be moved and resized as you see fit.

1 The Project Explorer

Opened from View > Project Explorer (or CTRL+R). The Project Explorer
works kind of like Windows Explorer, and shows you the Modules and
Forms that exist within each loaded project.

2 Properties Window

All “objects” have properties. The most basic is a Module which has one
property, its name. In our example from lesson 1, if you highlight the
module “Module1” you will see that the Properties Window displays:

(Name) Module1

To change the name of the module into something more meaningful, just
click on the name and change it. You can’t have spaces in Module names
(in fact spaces are frowned on generally in any name) so the normal
principle is to use “CamelCase” to distinguish words better.

3 Form Window

A Form is a dialogue box. You use Forms to communicate with the user,
to tell them things or to get them to make choices and enter information.

4 Forms Toolbox

When you have created a Form or highlight an existing one, the Forms
Toolbox will appear. This contains all the tools necessary to build items
on your form, including text labels, buttons, scrollbars, etc.

5 Code Window

Each Module and Form has a code window. You can open these by
double-clicking on a Module, or by right-clicking on a Module or Form in
the Project Explorer. The Code Window displays, well … the code!
6 Code Windows

You can have as many Code Windows open as you want.

7 Locals Window

Not always open by default (View > Locals Window), the Locals Window
shows all the currently active objects and their properties, along with any
variables you have declared. It’s a very useful window to have open when
you are checking out (debugging) how your macros work.

Let’s look at an example and see how each window works.

In Project Explorer (1) double-click Module1 to open the Code Window.


You should see the code you recorded in Lesson 1:

Firstly, lets give the Module and the Routine names we can refer to later.

In the Properties Window next to the (Name) property, click on Module1


and edit it to be ExampleModule. The listing in the Project Explorer will
automatically adjust to show ExampleModule.

In the Code Window, edit Macro1 to be ExampleSmartLine. The Code


Window works just like Notepad, but will correct your formatting for you
as you go along. For example, if you leave forget the brackets at the end
of the Sub-Routine name:

Sub ExampleSmartLine

as soon as you hit Enter, they will be added in for you:


Sub ExampleSmartLine()

Don’t worry about what the brackets do at this point.

The only other window we can check out at this point is Locals. Make
sure you have Locals open (View > Locals Window) and dock it
somewhere. At the moment it will be empty.

Make sure your cursor is somewhere in the ExampleSmartLine Code


Window and hit F8 (or Debug > Step Into). The first line of the Sub-
Routine will be highlighted:

Debugging will run through the code line by line so we can see what it is
doing and fix any problems should we need to.

As soon as you hit F8, the Locals Window is filled with our Sub-Routine
ExampleSmartLine (which contains <No Variables> if you click on the +
and three points which will be used to define the locations of each vertex
of the SmartLine. Click on the + next to each of those and you’ll see they
all have the same three properties, X, Y and Z which relate to the co-
ordinate location in 3D space for each point.

Get to

CadInputQueue.SendCommand "PLACE SMARTLINE"

and when that line has been run, switch back into MicroStation. The
Place SmartLine command will have started, and MicroStation will be
waiting for the first vertex. In the Locals Window, the X & Y values for
StartPoint and Point will have been set.

Carry on hitting F8 until you have reached the line

CadInputQueue.SendDataPoint point, 1

Once you have run that line, you’ll see MicroStation now has the first
point placed (at co-ordinates shown in the locals window for point.x,
point.y and point.z) and is expecting the second vertex or a reset.

Again, carry on through until the third

CadInputQueue.SendDataPoint point, 1

Each time the Point.X .Y and .Z lines are run, the values in the Locals
Window will update accordingly. MicroStation will have placed two
SmartLine segments and will be waiting for another point or a reset. At
this stage, the macro sends a reset through the

CadInputQueue.SendReset

command and returns to the default tool (normally Selector or


PowerSelector) with

CommandState.StartDefaultCommand
Finally End Sub tells VBA that the routine has finished processing and in
MicroStation we should have a SmartLine exactly as the image below,
from co-ordinates 7.3161,-4.8657 to 9.7970,-1.7892 to 14.9664,-2.9316.

Point2 is never used, but is created automatically by the VBA Project


Manager when I recorded the macro. That object is not needed so to
keep things tidy, it can be removed from the routine.

Edit the line

Dim point As Point3d, point2 As Point3d

to be just

Dim point As Point3d

If you Step through the routine again, you’ll notice that the Locals Window
no longer shows Point2.

And that’s probably enough for now. Next time how to start creating an
interface for your macro to start getting some input.

You might also like