|
-
Dec 22nd, 2018, 04:01 PM
#1
VB6 Automated Source Code Processing Helper
WORK IN PROGRESS
This is a work in progress - it does a pretty good job of doing what it is trying to do, but there are definitely holes in the implementation. If you can provide any source code that fails, I will be happy to fix my code to accommodate it!
WHAT IS THIS?
This project parses VBG & VBP files, building a list of all source code files (with limitations, see the KNOWN/EXPECTED PROBLEMS section below). You can then loop through each source file, and each line of code therein to perform just about any line-level custom processing you can imagine. The project includes fast PCRE2 regex support for finding matching lines of code (in forward and reverse directions).
When you find a line you are looking for, you can optionally replace the text with something else, and when you are done you can save the file back to disk.
A VERY VERY VERY IMPORTANT WARNING
YOU can destroy your source code files using this project as it allows you to modify source code and write it back to disk! Bugs (mine or yours) can be catastrophic, so please make sure you backup your source code before processing it!
NOTE: The included example parser does not modify source files and in my opinion can be considered safe for all uses. That said, I still always recommend having backups made before using this project on your source code.
I TAKE NO RESPONSIBILITY FOR ANY TERRORS THIS PROJECT MAY UNLEASH UPON YOUR COMPUTER/FILES - YOU HAVE BEEN WARNED!
EXAMPLE USES
I use this project for a number of processes on my main project, including:
- Find methods that call "Erl" but contain lines that are not numbered
- Finding missing GUIDs in methods where I reference a method GUID for logging/debugging purposes.
- Finding duplicate GUIDs (copy & paste errors) in lists of field codes, and replacing duplicates with new GUIDs.
- Finding methods that do not have an error handler active.
- Finding methods where I accidentally used the NEW keyword instead of RC5 regfree instantiation (which would cause problems after deployment since the libraries aren't registered on the end-user's computer).
KNOWN/EXPECTED PROBLEMS
I've only tested this project on my own source code, so I expect problems when you try it on your own projects with your own coding styles. I'm happy to fix these issues, especially if you provide code examples.
Handling source code saved in other locales has not been tested at all, and based on the conversation in this thread, I expect problems (possibly serious ones!).
The project currently only supports FRM, BAS, CLS, and CTL files. More exotic things like data reports, web classes, property pages, etc... are not yet supported.
PRE-REQUISITES
IMPORTANT: Ensure that all of the above DLLs are saved in the App\System\ folder.
For Krool's OCXs you will need to register both OCX files.
For Olaf's RC6, you will need to ensure you have registered it properly using the .BAT file included with the binary distribution.
USAGE
There's an included example processor class (CExampleProcessor) included in the project that demonstrates some of the features of the project. The example processor finds methods that do NOT include an "ON ERROR GOTO <label>" line, so it is useful for finding places you forgot to include an error handler.
To try it out, start the project then click Select Files and select any VBP or VBG file.
Once the list of files is parsed and populated, click the Run button and wait while the source files are processed by the CExampleProcessor class.
After processing is complete, click Copy to Clipboard to copy the report/log to the clipboard and paste it into your favourite text editor for review. In particular, look for WARNING lines.
BUILDING YOUR OWN SOURCE CODE PROCESSORS
NOTE: I'll expand on these instructions as the project matures.
To build your own source processor, add a class to the main VB6SourceProcessor project and implement the ISourceProcessor interface in the new class. In the ISourceProcessor_ProcessFile method, perform whatever physical line level pattern matching & processing you desire.
Remember to instantiate your class and call .ProcessFile on it in the frmMain.cmdRun_Click event!
FUTURE ENHANCEMENTS
- I would like to offer the ability to backup original source files before writing modified versions back to disk.
- I would like to add the ability to filter log messages by level (INFO, IMPORTANT, WARNING, ERROR), and maybe by keyword. ADDED IN LATEST VERSION
- I want to add the ability to cancel processing. ADDED IN LATEST VERSION
I imagine more enhancement ideas will come as people start using the project, so please let me know if you have any ideas on how to make the project better.
PROJECT SOURCE CODE
LATEST SOURCE CODE HERE: VB6SourceProcessor11.zip
Hope some of you find this project useful!
Last edited by jpbro; Jun 17th, 2025 at 11:36 AM.
Reason: Updated Project Source
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|