This next feature
on a scale of 1 - 10, where I suppose 10 is the
most important and most often used, this would be about a
2. It's a very obscure feature and it rarely comes in
handy. But when it does come in handy, it can absolutely save the day.
It basically allows you to get access
to the VBE. The VBE is the Visual Basic
Editor itself. You can get access to it programmatically.
Now this is nothing new for ProcessBook. Any good
ActiveX control container with scripting should be able
to do that. I will give you an example of how you
might use this. I have got a bunch of buttons here.
Let's just pretend that I do not just have 3 buttons,
I have 300 buttons and they are on multiple displays.
And I know there is a lot of code that is fairly
similar from one button to the next that I
need to insert into the
code panels that go with these buttons-- the click events.
As you can see right now, there is nothing that is
associated this button. I click on this and nothing at all happens.
What I would like to do is I would like to
insert the proper code into those buttons. Well,
I can do that by running a little
script. I am going to run a script called
test1 and as if by magic, notice that all of a sudden
it works. We are selecting the right
colors. I am now going to select similar
objects. It's selecting all the squares, now we will select
all the circles. And the reason we can do this is
because at this point,
basically what we have done is we have inserted
code into those code panels. So if I look at the Visual Basic
here, there are my command buttons. The
command buttons previously
had no code, but now
the code has been inserted in there. And it has been
inserted by getting access to the VB Editor.
Here is the code that we use to add things to
these code panels right here. What we are
doing is we are dimensioning a variable,
MyVBE as the Visual Basic Editor. We get access
to that by simply saying, MyVBE
is... We are establishing a reference
to the current ProcessBook applications
and the VBE Editor. Application.VBE.
Now that gives us the Visual Basic
Editor. We need to find the
individual code panes, and this entire thing that we are looking at here is a
code pane. And what we are doing is going into
VBE, it has a code panes collection, and we are going to get the
first item in that... And the
first item we are going to go into the code
module. And using a with statement, we are saying that everything
that happens within here, is going to be
done to this particular code module.
So we are looking at the
individual items, we are finding the items
using this Proc.BodyLine module.
We are finding
that item, that line number,
and then we are going an insert line using that
line number that we have derived from this command up
here. So we are inserting lines, select color,
select light and list objects.
These bits of code got added to
that command button. So if you will recall before, when
I clicked on the buttons, nothing happened. Afterwards this was inserted
in there so it ran the appropriate sub-routines which are also
included in this example. So that's an example of how
we can get access to the VBE.
If you have got some kind of a project where you really need some kind of a
code generator to edit 1000s
of links or what have you, this is a great way to go about it.
Here is another idea on how you
can make use of this feature. In many cases,
people when they find out how
much work they have to do basically to make
references to individual files. Like if I want to go
out and find or browse for that file
called MyUtils.PDI. People just do not
want to have to do all that work for 100s of
displays. And here is an example of how we can use the VBE
Editor to basically add
references. There is something called the
ActiveVBProject that has a references collection and
you can do an Add method that says add from
file. You simply use the name of the PDI file that will be added as a reference.
So to show you before and after,
right now I do not have any references
to MyUtils right here. I will go ahead and
execute this couple lines of code by pressing
F8 and stepping through it.
And at that point, as you can see, it just
went ahead and made the reference.
And if I go into Tools, References,
there it is. We have programmatically made a
reference to that. So if you are looking at
lots of shared code, and you do not want to do
that by hand, here is a programmatic solution.