BasicVBA 03 VBAEditor
BasicVBA 03 VBAEditor
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.
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
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.
Firstly, lets give the Module and the Routine names we can refer to later.
Sub ExampleSmartLine
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.
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
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.
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.
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
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.
to be just
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.