Create Addin for VBE Extensibility functions

J

Jack Leach

Hello again, intelligent people...

I'm interesting in creating an Addin for the VBE, from which I can utilize
the VBIDE model. Both of these are very new to me.

I have played around some with the VBIDE model and am fairly confident I can
accomplish my goal, but I would very much like to use this as an addin and
run it from a menu bar button.

I seem to be having some difficulty finding Access specific information for
doing so... can anyone possibly point me towards some useful literature? I
know next to nothing of Addins or how to create them thus far...

Also, if anyone is familiar with using the VBIDE to modify code, I wouldn't
turn down some advice: so far I have been able to accurately reference the
desired project, component, it's code, and specific procedures within the
code... at present I am trying to figure out how to manipulate specific lines
within the procedure. Specifically lines that are not comments. I have some
ideas on this, and will continue to try them out and hopefully come to some
conclusion, but if anyone happens to know off the top of their head it would
be a great help.

Many thanks to anyone who can offer some insight!

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
B

Banana

Not familiar with Add-Ins, sorry.

However the question about manipulating code inside a module object...

I of course assume you are making something like wizard that builds some
thing on the fly for the development and isn't something that's going to
be used at the runtime (e.g. data entry), yes?

Regarding the lines, I'm afraid it's fairly awkward as the only way to
manipulate something is by knowing what line you are on (you can also
add at the end of module without a direct reference)

That said, my usual method is to use a Do Until ... Loop with variables
maintaining a pointer to the current line.

Example:

Do Until l = MyModules.CountOfLines
If Left(Trim(MyModules.Lines(l)),1) = "'" Then
...
End If
l = l + 1
Loop


Note that you also can "skip" the looping slightly by looking up the
ProcCountOfLines (or something like that) to help you step through each
individual procedure once rather than looping every single lines. You
also can use this in conjunction with ProcOfBody (?) which tells you the
name of the procedure you're looking at so you can use that to "find" a
specific procedure, especially if you want to search for multiple but
similar procedures.

I hope this helps. :)
 
J

Jack Leach

I of course assume you are making something like wizard that builds some
thing on the fly for the development and isn't something that's going to
be used at the runtime (e.g. data entry), yes?

Correct.

Thanks for the input, this will help out a lot. My current goal is to be
able to find the "active" procedure (the one with the cursor) and loop its
lines. I think you've given me enough information to make learning the
process a lot easier.

Thanks!
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
B

Banana

I would be surprised if you could manipulate cursors. I went and looked
at the VBIDE, and the best I can find is determining an active windows
on the VBIDE but nothing that would pertain to the cursor. However,
there's methods for getting/setting selection, so that's the closest you
can get.

That said, I'd advise you to rethink this. You want your code-modifying
code to work blindly without human interaction, so it should be
programmed to find the right procedure without needing some one to
select the procedure. For example, if you want to write some code for a
certain control, it may make sense to have a toolbar button so you can
select the control, press that button and determine the control, then
find its procedures by checking its event handlers for any procedures or
function associated with it and using Find method of VBIDE.

Hope that helps a bit.
 
J

Jack Leach

Here's what I'm attempting to accomplish. Well it's a two part thing really:

1) Modify code from code... I've always wanted to try it but never got into
it (or had reason), so this is really mostly just for my own satisfaction and
experience.

2) In a recent post in the Forms Coding forum, op was having trouble with
the classic "understanding quotes in a string" dilemma (see Apostrophes
Problem posted yesterday). MVP Roger Carlson made note that what he does, is
types the all the code first, using a single quote, and goes back through to
change the single quotes into doubles. I thought this was an excellent idea,
far better than workarounds like Const Quo = """", etc, that you need to
adjust a little bit for in your code.

So I thought, how great would it be to have an addin for the VBE, click a
button and convert all of the apostrophe's that are not inside a commented
block into double quotes.

I had considered the possibility of some sort of automated Find & Replace
(I've seen a post within the past month related to automating this, but have
never done it myself), but the problem there is that FindReplace works inside
commented lines. So now I have reason to attempt to programmatically modify
code, with a possible end cause that might be very helpful to many people
struggling with how to do this.



I figured the best way to approach this would be in from a
procedure-by-procedure method. Doing the entire module at once might be a
little bit too much to mentally keep track of for any end-users of the addin.
If I can find the procedure that is currently being edited, without needing
something such as a const with the procedure name in each procedure, I can
loop the lines and replace the ' with "s

So if I can actually manage to make this work, that'd be great. It will
give me some experience editing code, and possibly even be able to offer an
add-in to the community to stab this quote issue that just about new
programmer has troubles with.

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
B

Banana

Jack said:
Here's what I'm attempting to accomplish. Well it's a two part thing really:

1) Modify code from code... I've always wanted to try it but never got into
it (or had reason), so this is really mostly just for my own satisfaction and
experience.

Fair enough. :) Always good way to learn more about stuff.
I figured the best way to approach this would be in from a
procedure-by-procedure method. Doing the entire module at once might be a
little bit too much to mentally keep track of for any end-users of the addin.
If I can find the procedure that is currently being edited, without needing
something such as a const with the procedure name in each procedure, I can
loop the lines and replace the ' with "s

Well, if you examine the VBIDE in the object browser, I am sure you will
find that you can get information on what is considered "active windows"
and use that to run through the module the active windows is associated
with. So doing it per-module or per-project is definitely doable.

As for doing it at per-procedure level, that's going to be a bit tougher
as I can't see any thing that would correspond to cursor. Maybe the
selection methods I mentioned earlier still works without any selection
being made? Try that out. Do poke around in the object browser; you may
get an idea.

Good luck!
 
J

Jack Leach

We shall see what I can come up with! (but probably not any time soon...)

Thank you Sir for your help.


--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
S

Stuart McCall

Jack Leach said:
http://www.databasedev.co.uk/access-add-ins.html

I was able to find some info on creating an add-in here. I haven't tried
yet but seems promising...

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)

Jack

If you'd like to see a very simple (& therefore easy to follow) Access
addin, you could try picking this one apart:

http://www.smccall.demon.co.uk/Downloads.htm#SQLFormat

The trick to getting Access addins to work is to get the UsysRegInfo table
correctly structured and filled. Here's the resource you'll need:

http://msdn.microsoft.com/en-us/library/aa155702(office.10).aspx
 
J

Jack Leach

Thanks Stuart.

I didn't know that an add-in could be "picked apart". I'll take a look.

I'll have to get back to this one though, in the meantime I'm researching
real-estate in Liverpool (he never said how long he'd be buying for) <g>

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
S

Stuart McCall

Jack Leach said:
Thanks Stuart.

I didn't know that an add-in could be "picked apart". I'll take a look.

An Access addin (as opposed to a COM addin) is just a database file, so you
can open it with shift held down as usual.

Have fun!
 
T

Tony Toews [MVP]

Jack Leach said:
Thanks for the input, this will help out a lot. My current goal is to be
able to find the "active" procedure (the one with the cursor) and loop its
lines. I think you've given me enough information to make learning the
process a lot easier.

MZtools doesn't do exactly what you want. But it does do similar
tricks. Such as it's find feature, which I much prefer over the MS
Find, which positions the cursor at the line of code.

How it does it I don't know. But Ricks Find and Replace does the
same think. If you do a find in a database, go to datasheet view of
the results and double click on the line he also positions the cursor
at the line in question.

So it's doable. I don't know how though.

Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top