PC Review


Reply
Thread Tools Rate Thread

Ascertaining whether a search in VBA code returns a string or a reserved word

 
 
Paul Martin
Guest
Posts: n/a
 
      30th Aug 2006
Hi all

I am writing some code that searches a VBA project for (in this case)
APIs and I am using "Declare" as the search criteria. If I find
"Declare", is there some way (perhaps an API) that can ascertain
whether the use of "Declare" is a string or a reserved word?

Now, I realise that if it is an API, it would be followed by "Function"
or "Sub". I have other search criteria that I also need to look for
(such as "Shell" and ".RegisterDatabase").

Any suggestions appreciated. Thanks in advance.

Paul Martin
Melbourne, Australia

 
Reply With Quote
 
 
 
 
Terry Kreft
Guest
Posts: n/a
 
      30th Aug 2006
I believe you would have to parse the line.

--

Terry Kreft


"Paul Martin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all
>
> I am writing some code that searches a VBA project for (in this case)
> APIs and I am using "Declare" as the search criteria. If I find
> "Declare", is there some way (perhaps an API) that can ascertain
> whether the use of "Declare" is a string or a reserved word?
>
> Now, I realise that if it is an API, it would be followed by "Function"
> or "Sub". I have other search criteria that I also need to look for
> (such as "Shell" and ".RegisterDatabase").
>
> Any suggestions appreciated. Thanks in advance.
>
> Paul Martin
> Melbourne, Australia
>



 
Reply With Quote
 
Paul Martin
Guest
Posts: n/a
 
      30th Aug 2006
Hi Terry

Could you please explain?

Thanks

Paul



Terry Kreft wrote:

> I believe you would have to parse the line.
>
> --
>
> Terry Kreft
>
>
> "Paul Martin" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi all
> >
> > I am writing some code that searches a VBA project for (in this case)
> > APIs and I am using "Declare" as the search criteria. If I find
> > "Declare", is there some way (perhaps an API) that can ascertain
> > whether the use of "Declare" is a string or a reserved word?
> >
> > Now, I realise that if it is an API, it would be followed by "Function"
> > or "Sub". I have other search criteria that I also need to look for
> > (such as "Shell" and ".RegisterDatabase").
> >
> > Any suggestions appreciated. Thanks in advance.
> >
> > Paul Martin
> > Melbourne, Australia
> >


 
Reply With Quote
 
pietlinden@hotmail.com
Guest
Posts: n/a
 
      30th Aug 2006
A line is made up of words, a combination of reserved words, variable
names, literals etc.
In order to determine if a word is reserved, you'd have to compare each
one to a dictionary, as in "If it's in the dictionary, it's reserved."

If you read an entire line of code, you could use Split to break the
line into an array of individual words (split on the space) and then
compare them to the dictionary.

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      30th Aug 2006
Can you look for it at the beginning of the line--after you trim any leading
spaces (and ignoring Public/Private key words)?

And I think you'd have to make sure a space character followed it.

And you may have to count quotes to see if you're in a string.

Dim myStr as string
mystr = "Do you have anything to" & _
" declare"





Paul Martin wrote:
>
> Hi all
>
> I am writing some code that searches a VBA project for (in this case)
> APIs and I am using "Declare" as the search criteria. If I find
> "Declare", is there some way (perhaps an API) that can ascertain
> whether the use of "Declare" is a string or a reserved word?
>
> Now, I realise that if it is an API, it would be followed by "Function"
> or "Sub". I have other search criteria that I also need to look for
> (such as "Shell" and ".RegisterDatabase").
>
> Any suggestions appreciated. Thanks in advance.
>
> Paul Martin
> Melbourne, Australia


--

Dave Peterson
 
Reply With Quote
 
Terry Kreft
Guest
Posts: n/a
 
      30th Aug 2006
I would but Piet has beaten me to it.

--

Terry Kreft


"Paul Martin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Terry
>
> Could you please explain?
>
> Thanks
>
> Paul
>
>
>
> Terry Kreft wrote:
>
> > I believe you would have to parse the line.
> >
> > --
> >
> > Terry Kreft
> >
> >
> > "Paul Martin" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Hi all
> > >
> > > I am writing some code that searches a VBA project for (in this case)
> > > APIs and I am using "Declare" as the search criteria. If I find
> > > "Declare", is there some way (perhaps an API) that can ascertain
> > > whether the use of "Declare" is a string or a reserved word?
> > >
> > > Now, I realise that if it is an API, it would be followed by

"Function"
> > > or "Sub". I have other search criteria that I also need to look for
> > > (such as "Shell" and ".RegisterDatabase").
> > >
> > > Any suggestions appreciated. Thanks in advance.
> > >
> > > Paul Martin
> > > Melbourne, Australia
> > >

>



 
Reply With Quote
 
Paul Martin
Guest
Posts: n/a
 
      31st Aug 2006
Thanks all for your responses.

I'm using the Find method of CodeModule using the WholeWord argument as
True, so there's no problem capturing the various search criteria, and
this is very efficient. I was wondering if there's some way that VBA
(or an API) would recognise the use of the word as a reserved word or
otherwise.

Based on the responses I've received, the answer appears to be no. All
the solutions are based on capturing a code line as a string.


Dave Peterson wrote:

> Can you look for it at the beginning of the line--after you trim any leading
> spaces (and ignoring Public/Private key words)?
>
> And I think you'd have to make sure a space character followed it.
>
> And you may have to count quotes to see if you're in a string.
>
> Dim myStr as string
> mystr = "Do you have anything to" & _
> " declare"
>
>
>
>
>
> Paul Martin wrote:
> >
> > Hi all
> >
> > I am writing some code that searches a VBA project for (in this case)
> > APIs and I am using "Declare" as the search criteria. If I find
> > "Declare", is there some way (perhaps an API) that can ascertain
> > whether the use of "Declare" is a string or a reserved word?
> >
> > Now, I realise that if it is an API, it would be followed by "Function"
> > or "Sub". I have other search criteria that I also need to look for
> > (such as "Shell" and ".RegisterDatabase").
> >
> > Any suggestions appreciated. Thanks in advance.
> >
> > Paul Martin
> > Melbourne, Australia

>
> --
>
> Dave Peterson


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      31st Aug 2006
I can't imagine that an API would care about the reserved words in Excel's VBA,
or MSWord's VBA, or PPT's VBA or AutoCad's VBA or any of the other flavors of
VBA.

It wouldn't make sense to me--but I've been wrong lots of time.

Paul Martin wrote:
>
> Thanks all for your responses.
>
> I'm using the Find method of CodeModule using the WholeWord argument as
> True, so there's no problem capturing the various search criteria, and
> this is very efficient. I was wondering if there's some way that VBA
> (or an API) would recognise the use of the word as a reserved word or
> otherwise.
>
> Based on the responses I've received, the answer appears to be no. All
> the solutions are based on capturing a code line as a string.
>
> Dave Peterson wrote:
>
> > Can you look for it at the beginning of the line--after you trim any leading
> > spaces (and ignoring Public/Private key words)?
> >
> > And I think you'd have to make sure a space character followed it.
> >
> > And you may have to count quotes to see if you're in a string.
> >
> > Dim myStr as string
> > mystr = "Do you have anything to" & _
> > " declare"
> >
> >
> >
> >
> >
> > Paul Martin wrote:
> > >
> > > Hi all
> > >
> > > I am writing some code that searches a VBA project for (in this case)
> > > APIs and I am using "Declare" as the search criteria. If I find
> > > "Declare", is there some way (perhaps an API) that can ascertain
> > > whether the use of "Declare" is a string or a reserved word?
> > >
> > > Now, I realise that if it is an API, it would be followed by "Function"
> > > or "Sub". I have other search criteria that I also need to look for
> > > (such as "Shell" and ".RegisterDatabase").
> > >
> > > Any suggestions appreciated. Thanks in advance.
> > >
> > > Paul Martin
> > > Melbourne, Australia

> >
> > --
> >
> > Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      31st Aug 2006
Paul,
You could check if the single line had a "Declare " and a " Lib " (note the
spaces) and compare text sensitive. Whilst not 100% conclusive, it would be
a pretty strange string to have both exactly like that.
Depending what you're after, maybe check it's not a comment first.

NickHK

"Paul Martin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks all for your responses.
>
> I'm using the Find method of CodeModule using the WholeWord argument as
> True, so there's no problem capturing the various search criteria, and
> this is very efficient. I was wondering if there's some way that VBA
> (or an API) would recognise the use of the word as a reserved word or
> otherwise.
>
> Based on the responses I've received, the answer appears to be no. All
> the solutions are based on capturing a code line as a string.
>
>
> Dave Peterson wrote:
>
> > Can you look for it at the beginning of the line--after you trim any

leading
> > spaces (and ignoring Public/Private key words)?
> >
> > And I think you'd have to make sure a space character followed it.
> >
> > And you may have to count quotes to see if you're in a string.
> >
> > Dim myStr as string
> > mystr = "Do you have anything to" & _
> > " declare"
> >
> >
> >
> >
> >
> > Paul Martin wrote:
> > >
> > > Hi all
> > >
> > > I am writing some code that searches a VBA project for (in this case)
> > > APIs and I am using "Declare" as the search criteria. If I find
> > > "Declare", is there some way (perhaps an API) that can ascertain
> > > whether the use of "Declare" is a string or a reserved word?
> > >
> > > Now, I realise that if it is an API, it would be followed by

"Function"
> > > or "Sub". I have other search criteria that I also need to look for
> > > (such as "Shell" and ".RegisterDatabase").
> > >
> > > Any suggestions appreciated. Thanks in advance.
> > >
> > > Paul Martin
> > > Melbourne, Australia

> >
> > --
> >
> > Dave Peterson

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple code that does a search for me and returns a string Southern at Heart Microsoft Excel Programming 4 13th Jan 2009 10:17 PM
Ascertaining whether a search in VBA code returns a string or a reserved word Paul Martin Microsoft Excel Programming 8 31st Aug 2006 07:33 AM
Re: Excel XP VBA code to search all macro code in Excel module for specific search string criteria Ed Microsoft Excel Programming 4 20th May 2004 02:08 PM
Re: Excel XP VBA code to search all macro code in Excel module for specific search string criteria Frank Kabel Microsoft Excel Programming 0 19th May 2004 08:11 PM
how to determine if string is a vba reserved word G. Stewart Microsoft Access 3 28th Nov 2003 01:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:05 AM.