Solved

Search TXT file for mult. lines and fill combo

Posted on 2008-06-17
7
159 Views
Last Modified: 2011-09-20
I need to search a txt file and read single lines from it. Below is a sample of a txt file i need to search. I need to put into a combo box the text after the "USName=". there could be one or 20 of these lines within the text file.

Thank you,

MaterialType=Miscl
SectionType=Appurtenance
AllowEdit=Yes
USName=ADC DB 800/1900 FB Masthead
SIName=ADC DB 800/1900 FB Masthead
Values=221.48 245.715555555556 28.7 39.7078240740741 271.195555555556 325.888888888889 450.208888888889 115.64 134.835555555556 155.275555555556 199.888888888889 304.048888888889 52.9323148148148 86.8090740740741 189.718148148148 14 11.3 5.9 1 0 0 28.7
USName=CG DD800 FB Masthead
SIName=CG DD800 FB Masthead
Values=179.732 201.727555555556 15.9 23.3909722222222 224.967555555556 275.180888888889 390.540888888889 60.522 76.4508888888889 93.6242222222222 131.704222222222 222.797555555556 32.774537037037 57.9972222222222 139.709259259259 13.1 9.8 3.3 1 0 0 15.9
USName=CG-1900DD-FULL-DIN
SIName=CG-1900DD-FULL-DIN
Values=185.094 207.182888888889 15 22.2401388888889 230.516222222222 280.916222222222 396.649555555555 45.864 60.0195555555555 75.4195555555555 109.952888888889 193.952888888889 31.3469444444444 55.9383333333333 136.076666666667 11.7 11.3 2.8 1 0 0 15
USName=DB 800/1900 FB Masthead
SIName=DB 800/1900 FB Masthead
Values=221.48 245.715555555556 29 40.0078240740741 271.195555555556 325.888888888889 450.208888888889 115.64 134.835555555556 155.275555555556 199.888888888889 304.048888888889 53.2323148148148 87.1090740740741 190.018148148148 14 11.3 5.9 1 0 0 29
USName=DD1900 FB Masthead
SIName=DD1900 FB Masthead
Values=185.094 207.182888888889 15.4 22.6401388888889 230.516222222222 280.916222222222 396.649555555555 45.864 60.0195555555555 75.4195555555555 109.952888888889 193.952888888889 31.7469444444444 56.3383333333333 136.476666666667 11.7 11.3 2.8 1 0 0 15.4
USName=DD800 Smartop TMA
SIName=DD800 Smartop TMA
Values=131.516 150.711555555556 23 30.2437037037037 171.151555555556 215.764888888889 319.924888888889 88.816 105.678222222222 123.784888888889 163.731555555556 258.558222222222 39.3087037037037 63.6803703703704 142.834814814815 12.2 7.7 5.2 1 0 0 23
USName=DD800 Full Band Masthead
SIName=DD800 Full Band Masthead
Values=182.476 204.658222222222 15.8 23.3823611111111 228.084888888889 278.671555555556 394.778222222222 61.446 77.5615555555555 94.9215555555556 133.374888888889 225.214888888889 32.8702777777778 58.3405555555556 140.703333333333 13.3 9.8 3.3 1 0 0 15.8

0
Comment
Question by:mattsteel
  • 5
  • 2
7 Comments
 
LVL 18

Accepted Solution

by:
jcoehoorn earned 500 total points
ID: 21807713
This should get the list, and you should be able to bind that list to your combobox.  

WARNING: I typed the code directly into the browser window so there might be a typo or other silly error:
Function GetUSNames(ByVal FileName As String) As IEnumerable(Of String)
   Const SearchText As String = "USName="
 
   Dim result As New List(Of String)()
   If Not IO.File.Exists(FileName) Then Return result
 
   Using reader As New IO.StreamReader(FileName)
       While Not reader.EndOfStream
           Dim CurLine As String = reader.ReadLine()
           If (CurLine.StartsWith(SearchText) Then
              result.Add(CurLine.Substring(SearchText.Length).Trim)
           End If
       End While
   End Using
   
    Return result
End Function

Open in new window

0
 

Author Comment

by:mattsteel
ID: 21807985
I placed your code into the sub, you did make any mistakes, but my beginning level has stumped me again. Ive paste what i have. when I  put in the function call 'E1Description1ComboBox.Text = GetUSNames()  the 'GetUSNames()'  is coming up with the following error.

Argument not specified for parameter 'FileName' of 'Public Function GetUSNames(FileName As String) As System.Collections.Generic.IEnumerable(Of String)'.

I know im doing somthing wrong.
Thanks
===============================================================================
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'TADDataSet.Table1' table. You can move, or remove it, as needed.
        Me.Table1TableAdapter.Fill(Me.TADDataSet.Table1)

        E1Description1ComboBox.Text = GetUSNames()
    End Sub

    Function GetUSNames(ByVal FileName As String) As IEnumerable(Of String)
        Const SearchText As String = "USName="
        FileName = "c:\adc.12.2007.bak"
        Dim result As New List(Of String)()
        If Not IO.File.Exists(FileName) Then Return result
        Using reader As New IO.StreamReader(FileName)
            While Not reader.EndOfStream
                Dim CurLine As String = reader.ReadLine()
                If (CurLine.StartsWith(SearchText)) Then
                    result.Add(CurLine.Substring(SearchText.Length).Trim)
                End If
            End While
        End Using

        Return result
    End Function
=====================================================================
0
 

Author Comment

by:mattsteel
ID: 21807998
Sorry, that is you DIDNT make any mistakes....
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:jcoehoorn
ID: 21808796
Well, first all it should be pretty obvious how to fix the error reported by the compiler.  Just read the message again, look at the function definition, and look at where you call it in your code.  You won't make it far working in .Net or many other languages if you can't use a function like this.

2nd:  the function I gave returns an IEnumerbale.  You're trying to assign it to what looks like a string property.  This is a little more forgiving, since IEnumerable is unfamiliar to a lot of new .Net programmers.  But I think google, msdn, or wikipedia could explain it better than I.
0
 

Author Comment

by:mattsteel
ID: 21813508
Im sorry for being Ignorant, but i just converted over from lsp programming. So if you could show me what you mean. And no, I havent made it far in vb yet. But with your help, I could be alittle closer. Iver searched the net for clues to start this fuction, but im unable to locate any thing.
0
 

Author Comment

by:mattsteel
ID: 21813747
GetUSNames(filename)
0
 

Author Closing Comment

by:mattsteel
ID: 31468147
Thank You, for making me search for the function call.  Like I stated, Im realy new to this VB stuff...but with help from you all, I hope to learn this quickly. Thanks again for your help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question