SonicBoomAu Posted March 21, 2005 Posted March 21, 2005 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 Quote 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
SonicBoomAu Posted March 21, 2005 Author Posted March 21, 2005 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? Quote 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
michael_hk Posted March 21, 2005 Posted March 21, 2005 Use one loop is enough Do Me.cboSystem.Items.Add(sr.ReadLine()) Loop Until input = "[TYPE2]" Quote There is no spoon. <<The Matrix>>
SonicBoomAu Posted March 21, 2005 Author Posted March 21, 2005 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. Quote 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
michael_hk Posted March 21, 2005 Posted March 21, 2005 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 Quote There is no spoon. <<The Matrix>>
SonicBoomAu Posted March 21, 2005 Author Posted March 21, 2005 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 Quote 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 Iceplug Posted March 23, 2005 Leaders Posted March 23, 2005 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. Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.