Initially, I was very encouraged as I read .NET's file operations. As someone with a background in UNIX, C, and Perl, I find filestreams a natural way to read and write to files. But I wouldn't be the one taking the class. What I found challenging on behalf of my beginner students is the lack of built-in file record parsing in .NET. In .NET, file reads bring in an entire line or an entire file. Splitting a record into its parts and then putting those fields into interface captions was a true challenge! This wasn't covered in many books at the time, including college textbooks.
The forums and code sites on the Internet discussed this problem in detail and offered several solutions. Let's review a few of these possibilities, with you acting in the place of a beginning programming student with little formal training in data structures.
If you have no easy way to parse the fields from a record, what do you do? After all, you're parsing in an entire line with .NET. The first set of examples to work around this issue recorded each field as a separate line of text—in effect, making the line ending a delimiter of sorts. When reading in the lines of text, the coder created loops to read in exactly the correct number of lines per record. This was a nice way to get around the issues, but one mistake soon rippled through the future reads. In other words, one skipped field, a skipped line, soon threw off that record and all other records. The looping required was difficult for many beginners. Error checking is difficult with this approach. It's all string data, so doing deep data validation is difficult. No, the level of complexity just seemed to be too much for what we were used to with the VB 6 example.
The second example was a brilliant one I found in the Deitel, Deitel, and Nieto textbook used in the .NET class. It was great. It used serialization and brilliant arrays. It was truly an excellent example for a more advanced class. Was it easy, fun and immediately understandable? Not for my 102 class.
This seemed to leave me with fewer and fewer alternatives.
So now I was left with some of my VB 6 background. VB 6 has a nice split function. Pass it a sentence with words separated by spaces, and VB 6 will give you an array with each word as an element in the array. More properly, the split function will return the fields once you define the delimiter used—maybe a space, a comma, or an ampersand. .NET has nothing to be ashamed of; it also has a SPLIT function that works exactly as I'd need it to do. Add in a few loops to go through an array created from a record delimited by a comma, and what elegance! What efficiency! What another example of complexity! After all, it seems odd to have to go into this kind of detail when my benchmark VB 6 code doesn't require it.
As you can see, bringing in these techniques seemed to go against the content needed for my 102 class. It was with a lot of sadness that I put away a final project that had been very popular for previous classes.
But now I'm dusting it off again. There's a new kid in town: the My object in VB 2005!