Can you Use StreamReader In Public Module / Function- I'm trying Loading Text Files In to a Combo Box vb.net

Ken808
Ken808 used Ask the Experts™
on
Hi Guys,

I have a program I'm working on with multiple combo boxes on multiple forms. A lot of the combo boxes are labeled the same name. Ie ComboBox1.

Can you Use StreamReader In Public Module / Function

 I'm trying Loading Text Files In to a Combo Boxes. I have multiple forms with same combo boxes. I would like to reduce the amount of code im using...

This is an example of how im reading my text file in to the combo box.

   Dim objReader_TextFile1 As New System.IO.StreamReader("c:\\Text_Files\TextFile1.txt")
             
                    Do While Not objReader_TextFile1.EndOfStream
                ComboBox1.Items.Add(objReader_TextFile1.ReadLine)
            Loop
            objReader_TextFile1.Close()

Or is there a better / different way of doing this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
Not sure it would really reduce code to move it to a module, when you can do it in one line like this:
ComboBox1.Items.AddRange(System.IO.File.ReadAllLines("C:\Users\mikes\Documents\somefile.txt"))

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial