How to open a file with VB Studio 2008

Just needing input. I am looking for how to open a txt file with VB Studio 2008. Simple in VB6 with the Open command and input statement but cannot find how to do this with VB Studio 2008.
VB6: Open "c:\folder\program.txt" for input as #1  - How about VB Studio 2008?
David WaltersWebsite AdminAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What type of solution are you working with in Visual Studio 2008 - Web Site, Windows Forms, Business Intelligence project etc.?

Depending on your Visual Settings you can work in C# or VB .NET to open a text file.

What do you need to do with the text file? If you are performing an ETL process, I would recommend just creating an Integration Services project in Visual Studio because there's connectors to work with text files...
David WaltersWebsite AdminAuthor Commented:
The text file I want to open is on C: drive. I want to place its contents in a textbox. Have started working with Visual Studio 2008 and am new to it. Need help getting the contents of the text into a textbox.
Jacques Bourgeois (James Burger)PresidentCommented:
Dim reader As New System.IO.StreamReader("c:\folder\program.txt")
            TextBox1.Text = reader.ReadLine

If you want to read the whole file instead of only the first line, call ReadToEnd instead of ReadLine.

Do not forget the Close. While is is automatic in VB6, you absolutely need to Close it in .NET. Otherwise, the file risk to be left opened and locked until you restart the computer.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

David WaltersWebsite AdminAuthor Commented:
Thank you for the code. That was excellent. Just beginning Visual Studio 2008 after working in VB6 for years. Thanks again.
Jacques Bourgeois (James Burger)PresidentCommented:
Just a little more to help you get started.

In .NET, you do not look for commands when you want to do something. You are always looking for a class. And because there are 10000 plus classes, they are divided into namespaces. Think of it as files that are divided into directories to make then easier to access.

Just as you do with files, where you first need to know the directory they are in before you use them, in .NET you first look into the namespace in order to find the class that you are looking for.

The System.IO namespace I used for my code contains most of the classes you might need to handle files. System.XML is more specific for XML files. System.Data would be the namespace in which you find the classes that deal with database access.

Once you know of a namespace, all you have to do is type its name, put the dot at the end, and there are the classes that you have available for the type of work you want to do. Once you have created and object of that class, you have its list of properties and methods. If you do not find in there what you need, look for other classes. For instance, in System.IO, there is the StreamReader that I used, but there is also a FileStream, a StringReader and a BinaryReader. Each class has its own specialized features, so one might be better than another in a given situation.
David WaltersWebsite AdminAuthor Commented:
Thank you so much for this information. It has helped me big time. Trying to wrap my mind around Visual Studio 2008 after many years with Visual Basic 6.0. It is definitely a different horse and you have helped greatly to open my eyes! Would I be greedy to say keep it coming!!! :)Thanks again.
Jacques Bourgeois (James Burger)PresidentCommented:
Not greedy, simply curious to know more. In my classes, these are the students I like the most to work with.

One thing though. If you are beginning, why stick with Visual Studio 2008. You are 3 versions back from the current one. Some of the stuff in 2008 is considered obsolete in more recent versions. If you do a lot of work on that one, you might end up having problems upgrading later if you skip many versions.

Unless you are restrained by running under Windows XP, you can have Visual Studio 2013 Express for free. The Express edition does not have all the extra tools that you find in more advanced editions, but it is more than enough for somebody who begins and would not know what to do with these extra tools anyway. They are only tools. The Express edition does not limit what you can do with your code in anyway.

And if you really want to go bigger, the old Professional edition is now available free under the name Visual Studio 2013 Community edition. The only limitation is that you cannot have more than 5 programmers using Visual Studio in your organization.
David WaltersWebsite AdminAuthor Commented:
Thanks for the heads up. I've download Microsoft Visual Studio 2013 Community edition and moved the code over to it.  Was staying with 2008 because I bought it with product key. Didn't realize 2013 Community edition was free. Wow that's great!! Will stay with 2013 from now on. Yes anxious is the right word!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.