[RESOLVED] Random Access Files - length of record?
Hey guys
I have, in past, when working with record data structure, used something like this
Code:
Private Type EmployeeRecord
EmpName As String * 20
JobTitle As String * 25
End Type
I have been told that the *20 / *25 (making the records a fixed length) is more efficient as then I can use:
Code:
Open "filename" For Random Access Read As #1 Len = 45
A few questions:
Firstly, is it possible to have records of a non-fixed length?
Secondly, why are fixed record lengths more efficient?
And my main question:
I intend to write a "Quiz" or "Test" program in VB6. Said program will allow one user to create a quiz with a combination of multiple choice questions and other questions that require an extended response (and "manual" marking). The questions will be saved to a file which is distributed to one or more "candidates" who can answer the quiz.
The first issue is that the questions (and answers) may be of many different lengths, from something as simple as "2+2" then "4" to a full "mini-essay" task. Would it be better practice to make my records a fixed length, something like 500 characters therefore 500 bytes for the question field, knowing that in many cases, about 480 of these bytes will sit empty? Or would a non-fixed length record be acceptable here?
Secondly, the "candidate" will need to answer questions in different ways - either "check the boxes" for a multiple-choice style question, or lots of writing for extended response questions etc etc.
I would quite like to create one neat "candidate's answer" file.
I would, then, require to write different record types to the same "answer file" I believe.
Is this possible? How would I, going through the file for "marking", determine whether the question we've just reached is a multichoice question therefore a multichoice record, or an extended response answer?
Is it possible to create a new "recordtype" in the "marking project" that is just one variable, for example, here is the 2 record answer file (pseudocode):
Code:
Multichoice A B # # E
Extendedresponse "long answer"
Then something like
Code:
Private Type FindQtype
Qtype as string
End Type
Code:
Dim questiontype as FindQtype
Open answerfile for randomaccess read as #1
Get #1, current_record, questiontype
If questiontype = multichoice then call multichoice marking module
Else if questiontype = extendedresponse then call extresp marking module
I'm not sure you have to go to as much trouble as you think with respect to the file access method.
For this type of application a straightforward sequential file (as you might create with Notepad) could suffice. There'd be 3 files, the Questions, the 'Student's' Answers and the Correct Answers. Obviously you wouldn't distribute the Correct Answers!
The Questions could be of any length as could the Answers. All you'd need to do, perhaps, is to have a 'flag' in each question which indicates what type of questions it is (eg Multiple Choice or 'extended' text for manual marking.) and in the case of Multiple Choice, what the choices are. You just need to define a format for the Questions
For example
Code:
Q1,M,4,What is 2 X 2 ?,3,4,1,7
Q2,T,Describe in no more than 100 words The Meaning of Life
Q3,M,3,How many Beans make 5?,3,6,5
Here there is a simple format:
The first field is the Question Number
The second is the type of question (M = Multiple Choice, T = Textual answer)
What follows depends upon the type of question
If the type is M then
the third field is the number of choices
the fourth is the question and the fifth onwards are the choices
If the type is T then
the third and final field is the question
In your program you could read a complete line from the file (using Line Input) and then Split it on Commas. (EDIT: That means that you couldn't use any commas in the text of the Question) That will create a dynamic array within which element 0 will contain the question number and element 1 the type of question. You can examine element 1 and then process the remainder of the array as desired.
I have attached a simple example program that would process such a format so you can have a play. It's not pretty (I don't do UI very well!) but there's enough to demonstrate the functionality and, perhaps, give you something to build on.
The answer file created follows nearly the same format as the question file so you can use the same technique(s) to process the answers.