We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,267 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to Read a File From From Multiple Folders In Visual Basic 2010.

Hello,

I'm currently making a program in Visual Basic 2010 for my Course work, and I'm struggling a little as it involves a "log-in system."

The system will save the Users Information in a folder (Called UserInfo.txt) (Address, Password, Email etc..), and the folder name being the username of the User.

When an Admin wants to view or edit a User, I want the Admin to be able to select the User from a drop-down list and when selected, the information of the user loads in and is displayed in the text boxes bellow (on the same form). The Information can then be edited and Saved back to the file of that user selected with a "Save" button.

Could somebody please help me, as I'm struggling!

Thanks a lot!

- Toby.

4
Contributors
7
Replies
1 Week
Discussion Span
1 Year Ago
Last Updated
10
Views
Question
Answered
Tobyjug2222
Newbie Poster
21 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You don't want to read a file from multiple folders, just to read a file and populate the appropriate textboxes. According to your specs there is only 1 file per directory and that is the userinfo.txt.
Since you are not giving any specs for the file itself read here: http://www.daniweb.com/software-development/vbnet/threads/134617 and here http://www.homeandlearn.co.uk/net/nets8p3.html for plain text file and here: http://www.daniweb.com/software-development/vbnet/threads/380681 for a csv file (I know the extension isn't csv, but still it's a text file).
For the users (which directory to use for reading the correct file), read here: http://msdn.microsoft.com/en-us/library/c1sez4sc.aspx or in general the directory class here: http://msdn.microsoft.com/en-us/library/system.io.directory.aspx

adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11

try this

public sub ListFiles()

'DIR for folder
'add each file to ListBox control

For each file as string in IO.directory.getfiles(Folder Path)
	Listbox.items.Add(file)
next

End Sub
ObSys
Junior Poster in Training
77 posts since Nov 2011
Reputation Points: 24
Solved Threads: 7
Skill Endorsements: 0

Thank you very much - both of you :)

Tobyjug2222
Newbie Poster
21 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Although @ Adam, I do want to take a file from multiple folders, because The same file name will be in all the folders, and this file will store all of the information about the user. When a Admin is to edit the users Info, he will select the username from the listbox (or the folder name) of the user, and then this will populate the textboxes bellow. When the data is edited, the Information will be resaved in the correct folder.

Following is the txtFile Layout:

Username (Tobyjug2222)
Password (hello)
Account type (Admin)
Reward Points (1000)
Tutor Room (12HY)
Date of Birth (02/01/94)
First Name (Toby)
Last Name (Daniel)
House Number (4)
Street (Yellow Brick Road)
Village (Old Village)
Town (Goonie)
County (Cheshire)
Post Code (CH1 6RB)


@Obsys, I was struggling to get your method to work because the reader wouldn't read it as a string, although it *was* decleared as a string.. when Debugging/ trying to find the error, I msgbox'ed the file path to see what it would display, and it gave me a "Argument 'Prompt' cannot be converted to type 'String'." & crashed.

Do you know how I can fix this? :o

Thanks

- Toby.

Tobyjug2222
Newbie Poster
21 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Try making a file with a list of all the usernames and there corresponding directory.
Populate the drop down box with this list of usernames.
When a name is selected then read the corresponding folder and open the file inside this folder.
There are tutorials everywhere for reading and writing from text files in VB .Net such as http://zorabyte.com/VBNETTutorials/ReadFileLineByLine.aspx

Let me know how it all goes!

Bernie.

berniefitz
Light Poster
36 posts since Jul 2011
Reputation Points: 17
Solved Threads: 7
Skill Endorsements: 0

Hi Bernie,

I was working on your Method over the last few days, and I created the file to store/ write all the users in, although I bumped into one problem, and that was how to give the User a path, that was connected to the username in that file.

Any way you know, on how to do that?

Thanks a lot!

- Toby.

Tobyjug2222
Newbie Poster
21 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I was thinking of setting the file with usernames and paths included.
e.g.

Username Path
bernie d:\somedir\users\bernie\
david d:\somedir\users\david
etc...

Just a tab delimited text file

Then read in the file and split the lines into a 2 element array. Do this in the load form section so it's ready to go when someone selects a user from your form.

Then, loop through the array when someone selects a user until you get to that user and use the path for however you want.

I hope I answered your question.

Let me know how it all goes.

Thanks, Bernie.

berniefitz
Light Poster
36 posts since Jul 2011
Reputation Points: 17
Solved Threads: 7
Skill Endorsements: 0
Question Answered as of 1 Year Ago by berniefitz, adam_k and ObSys

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1551 seconds using 2.71MB