1 Replies - 684 Views - Last Post: 06 February 2012 - 03:12 PM Rate Topic: -----

#1 papalocke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-February 12

text file from imbedded Resource into array

Posted 06 February 2012 - 02:49 PM

Hey guys im working on this project that I will be using for work at the college im employed at.
Im having problems with one section. I have imported 4 text files that have lists of computers in them, and i want to read the computer names into an array so i can use them from there. I have the attribute in them set as embedded Resource as well. So if anyone could check this code and see what is wrong or right, and how i can read the file into the array that is established that would be awesome.... Ill be researching this non stop untill i figure it out, but thought someone on here might have an idea. Thanks!
Private Sub bombardBTN_Click(sender As System.Object, e As System.EventArgs) Handles bombardBTN.Click

        Dim labSelected As String
        Try
            For i As Integer = 0 To labLB.SelectedItems.Count - 1

                labSelected = labLB.GetSelected(i)

                Dim fileText As Array
                Dim a As Assembly = GetType(Boximus).Assembly
                Using reader As New StreamReader(a.GetManifestResourceStream("Boximus." + labSelected + ".txt"))
                    'Need something here that reads that file into the Array fileText
                End Using

                MsgBox(fileText)

            Next
        Catch ex As Exception
            MsgBox(ex)
        End Try


    End Sub



This is a Button within the form that will process it when clicked.... :) Also FYI The project name is Boximus if that helps you determine whether im doing this right or not....

Is This A Good Question/Topic? 0
  • +

Replies To: text file from imbedded Resource into array

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9044
  • View blog
  • Posts: 33,951
  • Joined: 12-June 08

Re: text file from imbedded Resource into array

Posted 06 February 2012 - 03:12 PM

It's a pretty straight forward process. You have you file, you read it in with something like the StreamReader, and you add it to an expanding collection.

        Dim foo As New StreamReader("C:\test.txt") '-- stream reader with path to your file.
        Dim sArrayofStrings As New List(Of String) '-- Why not use a better resource than just "array"?
        Dim sTempIncoming As String = String.Empty '-- a holder for this example

        Do
            sTempIncoming = foo.ReadLine '-- get the line.
            sArrayofStrings.Add(sTempIncoming) '-- add to the colelction.
        Loop Until sTempIncoming Is Nothing '-- if nothing then you are not reading anything else in.

        '-- proof we have our lines.
        For Each temp As String In sArrayofStrings
            Console.WriteLine(temp)
        Next



input:
aaa
bbb
asdfasdf
here
there
trapped
alient


output:
aaa
bbb
asdfasdf
here
there
trapped
alient
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1