Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi All,

 

I am trying to search through a text file for heading [TYPE1] and then load the information under that heading into a combo box. Is this possible and what method would I use?

 

Here is an example of the text file:

 

[TYPE1]

Type A

Type B

Type C

Type D

 

[TYPE2]

Type A

Type B

Type C

Type D

 

[TYPE3]

etc....

 

 

The only way I can think of is using the following:

 

       Dim sr As StreamReader = File.OpenText(strFullPath)
       Dim input As String

           input = sr.ReadLine
           If input = "[TYPE2]" Then
                   ' loop through until input = ""
                   ' Somehow load the information into a combo box.
           End If

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Posted

After a bit of reading and searching the internet I stumbled across that helped and I was able to come up with the following:

 


       Dim sr As StreamReader = File.OpenText(strFullPath)
       Dim input As String

           Do
               input = sr.ReadLine()
           Loop Until input = "[TYPE2]"

           Do
               input = sr.ReadLine()
               Me.cboSystem.Items.Add(input)
           Loop Until input = ""

 

It works, but is there a better way of doing this?

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Posted
Use one loop is enough

 

Do
   Me.cboSystem.Items.Add(sr.ReadLine())
Loop Until input = "[TYPE2]"

But won't that populate the combo box with everything before "[TYPE2]".

 

Where as I require everything after "[TYPE2]" but not after "[TYPE3]", if that makes sense.

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Posted

I am trying to search through a text file for heading [TYPE1] and then load the information under that heading into a combo box.

You said you just want everything under [TYPE1].

 

i.e.

Type A

Type B

Type C

Type D

There is no spoon. <<The Matrix>>
Posted

You said you just want everything under [TYPE1].

 

"I am trying to search through a text file for heading [TYPE1]" [TYPE1] here was an example. Sorry If this got confusing. :) But

 

In my Code Example.

 

If input = "[TYPE2]" Then

' loop through until input = ""

' Somehow load the information into a combo box.

End If

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

  • Leaders
Posted

The code example looks fine. The only improvement that I can think of would be to have an if statement in the loop.

Do
 If someboolean Then  'is true when your type is found.
   'read line into line of text
   If lineoftext.Length = 0 Then
     someboolean = False  'stop adding to combobox.
   Else
     'add line to combobox
   End If
 Else
   'read line of text
   If lineoftext = "[TYPE2]" Then
     someboolean = True  'Start adding to combobox.
   End If
 End If
Loop Until SR.Peek = -1

something like that. It looks bigger, but it's only one loop.

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

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...