04-12-2003, 12:16 PM
Ok, ive created an electronic testing system for my A-Level computing coursework. Ive got all the test creation and testing parts done. Now i need to serch for particular results from a file.
Rite i have a results file that stores the pupils test information, such as the test they have taken, their name and score etc. Every time a user completes a test the results are appended to the results file.
How do i search this file for a particular test name and then display all the results of the users that have taken that test.
So in simple terms i want the teacher to be able to select a test and then all the results for that test to be displayed.
Hope you have some ideas?
Thanks in advance!
04-12-2003, 01:23 PM
Well, if you know what test you are looking for, then you can check the test name by reading in the file step by step (line by line :))and checking the text to see if it is the test. If it is, then you store the appropriate data somewhere...
04-12-2003, 01:30 PM
yeah i know what the test name is. I dont know how to read it in line by line or search it, that is my problem i dont know how to do it!
Could you write me some code that searches each line for test name (that i specify) and if the line contains the test name i want the data on that line to be saved to an array or something?
Can you help me please!!
04-12-2003, 01:37 PM
Well, I'll give you this much... search MSDN and try it out for yourself.
The worst you could do is Open the file For Output, which empties the file, so don't do that, or just make a backup
Open filename For Input As #1
Do Until EOF(1)
Line Input #1, Text
If Text = whatever Then
'I don't have a clue as to what you want
Also, there's a good file handling tutorial in the Tutor's Corner. You should check it out.
04-12-2003, 01:45 PM
i know with the line input the entire line is saved as a string. So how would i seperate the data fields within this string? Is there not another way?
Each result is on a new line, i just want it to search each result and if it it from the test 'testname' save the results from that line to arrays or variables. So then i am able to print all the results of people taking that particular test. You see if the line is just read in i cannot split the variables saved up and it would have "" surrounding the data and commas seperting them.
Please tell me there is an easier more efficient way, PLEASE!
P.S If the above doesnt make sence, just ask!
04-12-2003, 01:49 PM
Just remember this; text file access is sequential. This means that you must access the data line-by-line until you find what you are after.
04-12-2003, 01:52 PM
is it possible to find the number of lines in a file? because if it is possible i could use a for next loop to put the data in to arrays then serch the arrays instead of the file.
Tell me it is possible the find how many lines there are, you know you want to ;-)
04-12-2003, 06:22 PM
Well, yeah, but in order to do that, you have to read the whole thing in with Line Input. You might as well keep the lines that you are reading into an array and just set a counter. :-\
04-15-2003, 10:32 AM
Its sorted now, thanks for your help.