Docsity

Lab Exercise: Reading Data from a File in Visual Studio - Prof. Nancy Mccracken, Lab Reports of Information Technology

Toggle sidebar
bg1
IST 256
Lab Week 9, Part 1 – October 20, 2008
1. New Process for Starting and Saving Visual Studio Projects
So far, you have been saving your Visual Studio projects on the drive where you can store
all your work. It has a long name, so for purposes of discussion, I am going to call it the
H: drive.
In this section of the course, we are going to use Visual Studio to read and write data to
files, and the network security does not allow us to do that to the H: drive. It will only
allow it to the C: drive.
So for every project, you will put the project in a folder on the C: drive and work with it
during the lab. At the end of lab, you must copy or save the project to the H: drive, so
that it will be saved.
When you want to work on a project again, you must first copy it from the H: drive to the
C: drive, work on it, and then copy it back to the H: drive at the end.
2. Writing a program that reads data from a file
a. Go to the C: drive and make a folder at the top level with your name or userid,
something like: C:\njmccrac
b. Open Visual Studio and go to create a new project/solution When this Dialog box
opens,
i. name: pick a name for the project – something like Candy
ii. location: browse to the folder that you just made on the C: drive
OR, if your Dialog box doesn’t have a location box, just make the new Candy project as
usual, and then do
Save As – and save the project to your new folder on the C: drive.
c. Write an application that reads candy preferences from a file.
Make two Labels and two Buttons on the form that looks something like:
Candy Preferences
|__Read Preference From File__|
Display Preferences:
|_Close_|
pf3

Partial preview of the text

Download Lab Exercise: Reading Data from a File in Visual Studio - Prof. Nancy Mccracken and more Lab Reports Information Technology in PDF only on Docsity!

IST 256

Lab Week 9, Part 1 – October 20, 2008

1. New Process for Starting and Saving Visual Studio Projects

So far, you have been saving your Visual Studio projects on the drive where you can store all your work. It has a long name, so for purposes of discussion, I am going to call it the H: drive.

In this section of the course, we are going to use Visual Studio to read and write data to files, and the network security does not allow us to do that to the H: drive. It will only allow it to the C: drive.

So for every project, you will put the project in a folder on the C: drive and work with it during the lab. At the end of lab, you must copy or save the project to the H: drive, so that it will be saved.

When you want to work on a project again, you must first copy it from the H: drive to the C: drive, work on it, and then copy it back to the H: drive at the end.

2. Writing a program that reads data from a file

a. Go to the C: drive and make a folder at the top level with your name or userid, something like: C:\njmccrac

b. Open Visual Studio and go to create a new project/solution When this Dialog box opens, i. name: pick a name for the project – something like Candy ii. location: browse to the folder that you just made on the C: drive

OR, if your Dialog box doesn’t have a location box, just make the new Candy project as usual, and then do Save As – and save the project to your new folder on the C: drive.

c. Write an application that reads candy preferences from a file. Make two Labels and two Buttons on the form that looks something like:

Candy Preferences

|Read Preference From File|

Display Preferences:

|Close|

Leave lots of room for the Display Preferences label, so that you can put several lines of text there from the file.

d. Prepare a data file using Notepad, or other text editor that doesn’t add extra formatting. Do not use Microsoft Word!

On each line of the file, type the name of a person, just the first name is fine, followed by a comma, followed by the name of the candy bar that they prefer. Type in 5 or 6 lines of data. Here is an example:

Fanaz, Snickers Huron, Kit Kat Hassan, Reese's Cup Jamilla, Snickers Traquan, Milky Way Xzavier, Snickers

Notepad will automatically put in an character when you type Enter to get the next line. And Notepad will put an character at the end of the file.

Save this file and name it something like Candy.txt. It should be saved in your FileCandy project folder on the C: drive under subfolder named “bin\Debug”. The entire path will look something like:

C:\njmccrac\FileCandy\bin\Debug\Candy.txt