4 Replies - 313 Views - Last Post: 16 February 2013 - 10:15 AM Rate Topic: -----

#1 pjfatboy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 30-November 12

Resources file

Posted 16 February 2013 - 07:33 AM

Hi all,
I'm trying to populate a combo box from a text file I created in Resources. I know how to populate from a text file using StreamReader but not sure how to do it using a resource file. This is how I do it with the StreamReader...
Dim appPath As String = Application.StartupPath()
r = New IO.StreamReader(appPath & "Bodyparts.txt")
While (r.Peek() > -1)
    BPcmb.Items.Add(r.ReadLine)
End While
r.Close()


I did a google search but they all tell how to populate using my example above. Thanks for any help.

Is This A Good Question/Topic? 0
  • +

Replies To: Resources file

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3466
  • View blog
  • Posts: 11,760
  • Joined: 12-December 12

Re: Resources file

Posted 16 February 2013 - 08:20 AM

I just Googled "vb.net read resources file" and the very first link is

an SO reference

How many searches did you perform and what were your search terms?! :whistling:

The second line provides this quote:

Quote

If you added the file as a resource in the Project + Properties, Resources tab, you'll get its content by using My.Resources:

Dim content As String = My.Resources.data5
Click the arrow on the Add Resource button and select Add Existing File, select your data5.txt file.

Was This Post Helpful? 0
  • +
  • -

#3 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 278
  • View blog
  • Posts: 884
  • Joined: 01-February 13

Re: Resources file

Posted 16 February 2013 - 08:47 AM

Please read the link that andrewsw has given so you can understand it a little better. After that i am guessing you will be back to find out how to get rid of the newline character that is printed in the combobox. There may be a better way to do it but, here is an example of how i have done it before :

Chr(10) is the ascii value for newline.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim lines() As String = My.Resources.test.Split(vbCrLf)
        For Each line In lines
            ComboBox1.Items.Add(line.Trim(Chr(10)))
        Next
    End Sub


This post has been edited by IronRazer: 16 February 2013 - 08:50 AM

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3466
  • View blog
  • Posts: 11,760
  • Joined: 12-December 12

Re: Resources file

Posted 16 February 2013 - 09:37 AM

Chr(10) is the ascii value for line-feed. vbNewLine can be either carriage-return (chr(13)) or carriage-return + line-feed (chr(10)), and is system-dependent.

Split() already returns an array of strings, so unless you need to store this array for some reason, then it can be skipped:

        For Each line In My.Resources.test.Split(vbCrLf)
            MsgBox(line.Trim(vbNewLine))
        Next

Although, with this kind of process, if it works with Chr(10) rather than vbNewLine then I would probably leave as is.

If would probably work without the separate Trim() as:
        For Each line In My.Resources.test.Split(vbNewLine)

but I haven't tested this.

This post has been edited by andrewsw: 16 February 2013 - 09:42 AM

Was This Post Helpful? 0
  • +
  • -

#5 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 278
  • View blog
  • Posts: 884
  • Joined: 01-February 13

Re: Resources file

Posted 16 February 2013 - 10:15 AM

andrewsw,
"vbNewLine can be either carriage-return (chr(13)) or carriage-return + line-feed (chr(10)), and is system-dependent."

Yes you are correct i didn`t think about that.

"Although, with this kind of process, if it works with Chr(10) rather than vbNewLine then I would probably leave as is."

I have tried vbNewLine and it would not trim the carriage-return unless i used Chr(10).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1