Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

Search TXT file for mult. lines and fill combo

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
mattsteel
Asked:
mattsteel
  • 5
  • 2
1 Solution
 
Joel CoehoornDirector of Information TechnologyCommented:
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
 
mattsteelAuthor Commented:
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
 
mattsteelAuthor Commented:
Sorry, that is you DIDNT make any mistakes....
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Joel CoehoornDirector of Information TechnologyCommented:
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
 
mattsteelAuthor Commented:
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
 
mattsteelAuthor Commented:
GetUSNames(filename)
0
 
mattsteelAuthor Commented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now