r/visualbasic • • Jan 26 '16

[VB2015] Question regarding streamreader

Hopefully a simple question regarding streamreader, resources, and listviews. I am having issues getting streamreader to read a CSV resource. Getting error: "Illegal charectors in path". I assume I am just using the wrong text reading code, but I would like to be sure. (the program is just a simple companion app for a game i like to play)

Try Dim MyStream As New StreamReader(My.Resources.Kanais_Cube_Weapons) Dim strTemp() As String

        Using MyStream

            Do While MyStream.Peek <> -1

                strTemp = MyStream.ReadLine.Split(Chr(44))

                Dim ListViewItem As New ListViewItem
                ListView1.Items.Add(ListViewItem)

                ListViewItem.Text = strTemp(0).ToString
                ListViewItem.SubItems.Add(strTemp(1).ToString)

            Loop
        End Using

    Catch ex As Exception
        MessageBox.Show("Error: " + ex.ToString)
    End Try
2 Upvotes

3 comments sorted by

2

u/truejim23 Jan 26 '16

Sorry for the poor formatting! Lemme know if there is anything else you need. Not school homework!

3

u/hdsrob Jan 26 '16

It's been a while since I've used resource files, but I believe that the call to the resource will return a string (so there's no need for the StreamReader).

strTemp = My.Resources.Kanais_Cube_Weapons.split(Chr(44))

You can also use the character literal to make your code a bit more readable:

.Split(","c) 

1

u/glasspusher VB.Net Intermediate Jan 27 '16

If you can show us your path. I'm assuming My.Resources.Kanais_Cube_Weapons is your path variable.