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)
"Banana" wrote:
> 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.
>
>
> Jack Leach wrote:
> >> 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!
>