The Project
When I inherited the class, no file operations were taught. So early on, I took the class on a stroll through sequential access files. As a final project, students would repair and enhance application pieces I gave them. They would put together a testing application that would read a line of text from a specially prepared file. Each line (record) consisted of a question and four foils (answers) from a comma-delimited file. The last field would be the correct answer. These values would be placed into the caption property of labels. So, magically, when the Caption's click event was triggered, the application would display the question and the four answers and let the user select one answer.
Once clicked, the caption text was stuffed into a variable called strGuess, and processing would shift to a Check subroutine, which would compare the strGuess to the correct answer string, itself fetched from the file. If these two strings matched, the score would move up by one. So the students found a lot of laughs changing the feedback strings to something sensitive like, "Wow, you suck at this!" They enjoyed tracing execution from interface to subroutines. Best of all, it was up to the students to use those phenomenal interface tools to create an exciting game-like interface that would hook a user into using the app.
Afterwards, the application was theirs to use to prepare for tests and quizzes in the future. Type up an appropriate set of questions and answers, and voilà! The application would help students learn. Rumor has it that one enterprising student sold his work to some pre-med, pre-law, pre-something students.
All this coding was simple to do in VB 6. Let's discuss that coding in detail. Once you see how simple VB 6 made this processing, you'll sense the challenges to coding it with .NET. But you'll see the fantastic improvements in VB 2005.
The question and four foils need to be placed into the labels' caption property programmatically. The correct answer needs to be stuffed into a variable. Opening a file in VB 6 was easy. Parsing the fields of a comma-delimited file record into distinct variables was easy as well. Most of us remember these lines very well, assuming that the file opened is #4:
Input #4, ques, foil1, foil2, foil3, foil4, Answer
And now, after parsing our strings into variables, we could thunk them into interface pieces like so:
strAnswer = Answer lblQuestion.Caption = ques lblFoil1.Caption = foil1 lblFoil2.Caption = foil2 lblFoil3.Caption = foil3 lblFoil4.Caption = foil4
Easy steps created a nice insertion of file data into label captions. Wrap a loop around the process of reading from the file, and soon you had winning apps with names like "The Quizmonator," "Testing Station," and "Tester 5000—The Application for Serious Testees." (I get some slightly wild students fresh from their fraternities.) It was great fun and seemed worthy enough to carry it forward to the first .NET class. But here's where I found Visual Basic .NET a bit daunting. Perhaps too challenging for new students?