TextTool: Access 97 DB For Working With Text Files

Category:
Office/VBA
Type:
Applications
Difficulty:
Intermediate
Author:
Gary Walter

Version Compatibility: Visual Basic 6

More information:
Since I started working with Access, I seem to have gotten more than my share of projects that required parsing huge text files into Access tables (the kind that are so big you have to use Word and it takes 5+ minutes for them just to load). Many have come from Unix, may have strange chars in them, may end each "line" with only LF (no CR), and are almost always never neatly delimited.

This db started out as a way to get a small "piece" of one of these text files to play with without going through Word. You can set "To Line No:" to say 300, and get the first 300 lines of the text file ("Get Text Lines"). This get routine uses "Input#" so each line is stripped of the ending CRLF. But if you have a file with no CR's, getting one line will attempt to get the whole file in one record!

So I added a "Get Bytes" routine that determines it has reached the end of a line when it encounters a LF. This routine uses the Get method so it turned out it was a whole lot faster getting a "piece" of the text file out of the middle or at the end (seems counter-intuitive when dealing with bytes instead of lines).

For example, if I have a text file that is say 11,525,535 bytes, to get the last 535 bytes, I set "From Byte No." to 11,525,000, the routine goes "straight to" byte 11,525,000 and starts processing.

Sometimes it is not obvious what chars I'm working with, so I turned it into a quasi-hex reader. This allows you to click anywhere in a line and see what the ASC value is. Or you can use the arrow buttons to move through the text line.

The save routine saves byte-for-byte what's in the textlines to another text file. One problem was when had used "Get Text Lines" so needed to add CRLF back to end of each line. So I created an "Adjust" routine that verifies that each text line ends in a CRLF. Along the way it also weeds out any chars not supported in Windows and the BackSpace char.

In order to simplify the hex-reader routines, I made the text line text box uneditable. That meant I could not do a quick paste of some text from the clipboard. So I added another routine to import the text on the clipboard.

This has turned into a decent tool that I have found myself using alot and thought it might be worth sharing.


Instructions: Click the link below to download the code. Select 'Save' from the IE popup dialog. Once downloaded, open the .zip file from your local drive using WinZip or a comparable program to view the contents.

Download texttool.zip