FixCode Version 1.3
===================
Written by Donn Edwards <donn@support.co.za>
Copyright (c) SOS Support Operating Systems. All rights reserved.
You may use it for its intended purpose, and may distribute it as freeware to your freinds 
and colleages. Public distribution may only done with the express permission of the author.

http://www.freevbcode.com/ShowCode.Asp?ID=1362

Pupose:
=======
This program is designed to make changes to VB forms, modules, or any other text file. 
For example, I use a program called VBeXpress 2.0 (http://www.vbexpress.com) to generate 
my database application. Then I use FixCode to add in custom buttons and code that isn't 
part of the generated application but I've added during the 'tweaking' process afterwards.

You can also specify a list of files that require the same change in each file. And you can 
use wild cards with the [FileDir] keyword.

There are 4 sample files that should be placed in a subdirectory called "StandardEXE" 
to illustrate how the program works.

You specify the changes required by constructing "find" and "replace" strings. For your 
own sanity, make sure that you can't repeat the change. See the examples below. The 
control file is set up like this:
>>>
[File]
Form1.frm

[Find]
A few lines of code

[Replace]
Some other lines of code

[end]
<<<
The default control file is called c:\dev\mapstudio\control.ini
This contains a set of changes to be made to files in the 
c:\dev\mapstudio\StandardEXE\ directory.

If you choose another control file, it will assume the changes are to be made to a 
subdirectory called StandardEXE. If this is not the case, then you'll need to specify 
the correct path.

For example, if you wanted to change the following (generated) code:
>>>
Private Sub Normal()
  '// The normal font
  with MDIMain.Preview1 ' MDIMain.Preview1
    .FontName = "Monospac821 BT" 
  end with ' MDIMain.Preview1
End Sub
<<<
To read:
>>>
Private Sub Normal()
dbug "Normal"
  '// The normal font
  with MDIMain.Preview1 ' MDIMain.Preview1
    .FontName = "Monospac821 BT" 
  end with ' MDIMain.Preview1
dbugout
End Sub
<<<
Then it is best to replace the entire block of code, because once the change has been 
applied, it can't be applied again, because the "find" part doesn't exist any more.

>>>
[File]
Form1.frm

[Find]
Private Sub Normal()
  '// The normal font
  with MDIMain.Preview1 ' MDIMain.Preview1
    .FontName = "Monospac821 BT" 
  end with ' MDIMain.Preview1
End Sub
[Replace]
Private Sub Normal()
dbug "Normal"
  '// The normal font
  with MDIMain.Preview1 ' MDIMain.Preview1
    .FontName = "Monospac821 BT" 
  end with ' MDIMain.Preview1
dbugout
End Sub
[end]
<<<

If you tried something like this:
>>>
[Find]
Private Sub Normal()
[Replace]
Private Sub Normal()
dbug "Normal"
[end]
<<<

Then each time you run the program you'll add *another* dbug line to the code. Fix it by 
changing the find string to include at least one line before and one line after the 
inserted line, such as:
>>>
[Find]
Private Sub Normal()
  '// The normal font
[Replace]
Private Sub Normal()
dbug "Normal"
  '// The normal font
[end]
<<<

If you wanted to make the changes to more than one file, you can use the 
[FileList] keyword to apply the same changes to several files, instead of just the [File]
keyword.

>>>
[FileList]
frmRetail.frm
frmRetailIst.frm
MDIMain.frm

<<<
Similarly, you can use the [FileDir] keyword to specify a whole bunch of files, restricted
to a single directory. In this case all 3 CR LF sequences are replaced with 2 CR LF 
sequences in all the frm and bas files.
>>>
[FileDir]
*.frm
*.bas

[Find]



[Replace]


[end]

<<<


A few rules:
1. You can only find and replace whole lines of code.
2. You must specify the file at least once. Thereafter all other changes will happen
   to the same file until you supply a new file name.
3. The [end] keyword is useful to indicate the end of the [Replace] section.
   It has no other significance.
4. You can "comment out" a [Find] and [Replace] pair by putting some other character
   after the [, such as [;Find] or [.Find]. For your own sanity do the same with
   [.Replace] as well.
5. There is no limit on the size of the control.ini file, other than what your text
   editor program is comfortable with.
6. If you specify a [Find] string which has several matches, all of them will be 
   replaced in the specified file. Try to be specific, and check the files.
7. Make a backup with WinZip or some other suitable program *before* you apply your changes.

Note: any changes that do not change the size of the file will be noted in the FixCode.txt 
file. Not all changes will affect the file size, but it's the only way of working out 
whether the changes were applied. So check this file and see if the changes were applied 
or not. The reason for doing this is that you don't want to assume some changes were 
applied when in fact they weren't.

If you run the application from within Visual Basic you can track the debug.print 
statements if you think the program is misbehaving.

Design Limitation:
==================
Please don't expect it to work with enormous text files. I was pleasantly surprised to 
find that it worked on an 84k file, when I had only expected it to work on a 64k file. 
So if your target file gets truncated, then restore a backup and find another way of 
making routine changes to it. Sorry!

Legal Liability:
================
This program is supplied "as is", with no warranty, either express or impled. No liability 
will be accepted for this code. You get the idea ;-)
You are welcome to study the code and make improvements. I would be interested to hear 
what you did to make it work better/faster or whatever.

Installation requirements:
==========================
Microsoft Visual Basic 6.0 SP3 or the Visual Basic 6 runtime library.
COMDLG32.OCX  (137k, 07-May-1999 0:00) in c:\windows\system\ (Windows 98 setup)

I recommend you download "EditPad" from TUCOWS or http://www.jgsoft.com and use it to 
edit .ini and .frm files. It is a small, efficient notepad replacement and it makes the 
job of manipulating these files (outside of the VB environment) a whole lot easier.

Version History:
================
1.1: Added in multiple file list [FileList]
1.2: Fixed up sample data for www.freevbcode.com, added in the double-click facility
     where double-clicking on the file name or directory opens them
1.3: Added in [FileDir] facility, as well as remembering whether the file was opened 
     before. This speeds up the processing time. 
     When no changes are made the colour of the counter goes blue. Log "blue" find 
     patterns in FixCode.txt. Compare emthod changed from binary to Text method, to 
     avoid irritating errors with mixed case.

July 2000
Donn Edwards