Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Gurus*
Posted

Once you've opened the file you can read it in line by line, but it's 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:

 

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();

 

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted (edited)

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

Edited by Phil_C

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...