• Noob question about file I/O in visual basic
    2 replies, posted
I have a problem with file I/O, What I want too do is take a file that looks something like this: [url=http://i.imagehost.org/view/0545/Unbenannt_1][img]http://i.imagehost.org/0545/Unbenannt_1.png[/img][/url] and have each word in a different textbox like this: [url=http://f.imagehost.org/view/0974/Unbenannt1][img]http://f.imagehost.org/0974/Unbenannt1.png[/img][/url] But instead of putting them in there, the user gets one of the words randomly and has to type in the corresponding words in the other textboxes. If he is correct he has to do the same for the next 4 words in the next line. I have been looking all over the internet for an answer of some sort, but all that I could find is tutorials for reading a whole file and putting it in a single textbox. Thanks in advance. Maybe I get less rainbows if I rephraise a bit, I don't want anyone to write the program for me, i just want to know how to get the I/O part of it working.
First of all I would make your file comma separated, IIRC visual basic has functionality to read the next element of a comma separated file. You would use a loop to read each 'word' into the array which will be x by 4, where x is the number of lines in the file (you may need to write a function to calculate this). [code] int i = 0; for i = 0 to NumberOfQuestions { int j = 0 for j = 0 to 3 { QuestionArray[i][j] == File.ReadElement // where file is the text file you have opened, and ReadElement is the function to read the next element in the comma separated file } } [/code] When the ok button is pushed you have the input checked with the contents of the array. For example: [code] // Question number is 4 in this example if Text1.Test == QuestionArray[4][1] && Text2.Test == QuestionArray[4][2] && Text3.Test == QuestionArray[4][3] then { // Correct! } else { // incorrect } [/code] Syntax is definitely wrong, I've never used VB.net (I'm assuming you are using that) and it's been a long time since I have used VB6.
I'll be quite honest, I missed the lesson in CSVs when I was learning VB.NET. However, I can correct a little bit of this syntax for ya. [code]'I'm assuming you've called your instance of the StreamReader 'File', as Mattz used. Dim i, j As Integer for i = 0 to NumberOfQuestions for j = 0 to 3 QuestionArray(i, j) = File.ReadElement 'I don't know this command in VB.NET. Next Next[/code] [code]' Question number is 4 in this example if (txt1.Text = QuestionArray(4, 1)) And (txt2.text = QuestionArray(4,2)) Then 'You can put more stuff in here with And. 'Stuff that happens if it's correct. else 'Stuff that happens if it's not. end if[/code] Good luck!
Sorry, you need to Log In to post a reply to this thread.