So, for now let's accept that you are stuck with this awful design. And that you haven't got the time, resources or expertise to refactor or rewrite. You need to automate the annual change.
It's difficult to suggest a firm solution without knowing more about the code. But let's assume that you have something like this:
[tt]USE Sales_2024 IN 0 ALIAS sales[/tt]
and you need to change it to this scattered around your code:
[tt]USE Sales_2025 IN 0 ALIAS sales[/tt]
And that you have many other changes to make of a similar type.
Start by identifying every instance of the code that needs changing. This is a one-off task, and is the same as you would need to do in any case every year if doing it manually. In each case, note the name of the PRG and the actual code that needs changing.
Then write a VFP program that takes in turn each of the relevant PRGs and reads it into a variable. Use FILETOSTR() for that. Then use STRTRAN() to find and replace the year numbers in each of the relevant lines of code. So something like this:
Code:
lcPRG = FILETOSTR("SalesProg.PRG")
lcOldYear = "2024"
lcNewYear = "2025"
lcOldCode = "USE Sales_" + lcOldYear + " IN 0 ALIAS sales"
lcNewCode = "USE Sales_" + lcNewYear + " IN 0 ALIAS sales"
lcPrg = STRTRAN(lcPrg, lcOldCode, lcNewCode)
* Repeat the above for each of the relevant lines of code.
* Then write the code back to the file
STTOFILE(lcPrg, "SalesProg.PRG")
* Repeat for each program
Clearly writing this program will involve some effort, but it will be a one-off task. Once you have done it, you can just run the program every year, only needing to change the values of lcOldYear and lcNewYer.
Note that the above is not production code. It is only meant to give you the general idea. You will of course need to attend to taking suitable backups, and also recompiling the programs and rebuilding the project.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads