UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> How To Count Occurences Of A String Within VBA Modules, Any Version    
 
   
Jaiket
post Feb 23 2019, 11:28 AM
Post#1



Posts: 385
Joined: 3-May 17
From: France


Hi,
I just stumbled upon a hack to do this, albeit a somewhat risky one, which should only be done on a copy of the database.

Search for the string, and replace it with the same string. The number of replacements is your count.

I guess it would work with any version of Access that has search and replace.

--------------------
Life is too short to drink bad wine.
Go to the top of the page
 
theDBguy
post Feb 23 2019, 11:30 AM
Post#2


Access Wiki and Forums Moderator
Posts: 76,425
Joined: 19-June 07
From: SunnySandyEggo


And why do we need to know "how many" occurrences there are? Just curious... considering the risks?

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
Jaiket
post Feb 23 2019, 12:16 PM
Post#3



Posts: 385
Joined: 3-May 17
From: France


Well the reason I looked was because I might add a "k" to the beginning of my names if they are a key in a variable. I then thought I could search for " k" to find those variables in my code. K being a pretty rare letter, I thought I'd just see how many were already in my code, and I came up with this way.

When I shut down Access, I was surprised at the number of objects which needed to be saved, but I now realise it was all my code modules, because of this search and replace.

Search and replace being a dangerous thing to use, one other option is manually refactoring. Counting occurences of strings on a copy of the database could be useful in identifying how long a manual refactor may take, maybe?

And I must admit that plugging things back into themselves to see what happens is a hobby of mine. The first ever music video (Bohemian Rhapsody) uses this kind of trick, filming the very screen that the recorded film is being shown on. Then there's guitar feedback.

You should of course be very careful - one of my vacuum cleaners disappeared when I did this to it.

--------------------
Life is too short to drink bad wine.
Go to the top of the page
 
Jaiket
post Feb 23 2019, 12:18 PM
Post#4



Posts: 385
Joined: 3-May 17
From: France


For anyone who has not a full understanding of English and our love of being silly - the last line of my last post is a joke.

--------------------
Life is too short to drink bad wine.
Go to the top of the page
 
theDBguy
post Feb 23 2019, 12:27 PM
Post#5


Access Wiki and Forums Moderator
Posts: 76,425
Joined: 19-June 07
From: SunnySandyEggo


Hi. Thanks for the explanation. Good luck with it.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
GroverParkGeorge
post Feb 23 2019, 01:00 PM
Post#6


UA Admin
Posts: 35,902
Joined: 20-June 02
From: Newcastle, WA


I assume this is related to the other thread regarding adding a "K" either as a prefix or as a suffix to an existing variable name to flag primary Keys and foreign Keys.

Getting a count of such occurrences would be of benefit exactly how? Would it tell you you had missed one? How would you know that?

Ranked on a scale of 1 to 10, 1 being a total waste of resources and 10 being essential to success, this seems like maybe a 2 or 3. Interesting artifact? Maybe. Useful as a programming tool? Meh.

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    23rd October 2019 - 04:55 PM