Text File read

Phil_C

Member
Joined
Mar 21, 2003
Messages
11
Location
Australia
I am new to Vb and I am trying ot get some text form a text file into textboxes and comboboxes.
I have the following text in a text file;
kuid <KUID:86105:546>
obsolete-table {
0 <KUID:86105:99999>
1 <KUID:86105:99999>
2 <KUID:86105:99999>
3 <KUID:86105:99999>
}
username 346
description "Item description"
build 3465
category-class 3456
category-region-0 US
category-era-0 1900s

What I need to do is read the text into vb maybe using the streamreader function and an array and then search the text for a text string for example "build" and then place the rest of the line into a text box or a combobox. Also in the case of the description the text to be placed in a textbox may be up to 200 characters and several lines in length but will always be between double quotes. How would I go about this? The lines of text may not always be in the order written above.

Thanks in advance

Phil
 
Once youve opened the file you can read it in line by line, but its going to be up to you to write the parsing logic to handle the context within the file. To open a file and read it line by line you do this:

C#:
StreamReader sr = new StreamReader(@"c:\myfile.txt");
string line;

while (sr.Peek != -1)
{
	line = sr.ReadLine();
	// Do what you like with the line
}

sr.Close();

Code:
Dim sr As New StreamReader("c:\myfile.txt")
Dim line As String

Do While Not sr.Peek = -1
    line = sr.ReadLine()
     Do what you want with line
Loop

sr.Close()

There are other methods of StreamReader you could use, such as ReadBlock, ReadToEnd and Read.
 
Thanks divil
This works and I can get the last line into a text box, but how do I search for a word and put the rest of the line into a textbox.

Thanks

Phil
 
Last edited by a moderator:
Back
Top