Sign in with
Sign up | Sign in
Your question
Solved

VB.Net Beginner Help

Last response: in Applications
Share
April 14, 2012 11:58:18 PM

I'm not that good with VB.Net although I've been working on this program of mine for quite some time and I've learned a great deal since I started. I'm using VS 2010 Professional and .net 4, I've got my program working but I'm trying to add some things that would better inform the user what's going on.

Basically I have the button_click baking up some files from a folder and I'm trying to get the output to show up in a richtext box.

This is what I have so far.



'Obtains the path to the desktop
Desktop = My.Computer.FileSystem.SpecialDirectories.Desktop
'Obtains the username for access to the appdata folder
User = My.Computer.FileSystem.GetParentPath(Desktop)
'Obtains the Systemdrive for backup storage
Drive = My.Computer.FileSystem.GetParentPath( _
My.Computer.FileSystem.GetParentPath(User))

TextBox2.Text = My.Computer.FileSystem.ReadAllText(Drive & "\Test\Test.config")
Dim svr As String
Dim filenames() As String = Directory.GetFiles(Drive & "Test\BackedFiles\Server\")
Dim i As Integer
svr = TextBox2.Text
i = 0
For i = 0 To filenames.Length - 1
output.Text = Path.GetFileName(filenames(i))
output.Refresh()
Next (i)
My.Computer.FileSystem.CopyFile(svr & "\banned-ips.txt", Drive & "BackedFiles\Server\banned-ips.txt", overwrite:=True)
My.Computer.FileSystem.CopyFile(svr & "\banned-players.txt", Drive & "BackedFiles\Server\banned-players.txt", overwrite:=True)
My.Computer.FileSystem.CopyFile(svr & "\ops.txt", Drive & "BackedFiles\Server\ops.txt", overwrite:=True)
My.Computer.FileSystem.CopyFile(svr & "\server.log", Drive & "BackedFiles\Server\server.log", overwrite:=True)
My.Computer.FileSystem.CopyFile(svr & "\server.properties", Drive & "BackedFiles\Server\server.properties", overwrite:=True)
My.Computer.FileSystem.CopyFile(svr & "\white-list.txt", Drive & "BackedFiles\Server\white-list.txt", overwrite:=True)
My.Computer.FileSystem.CopyFile(svr & "\Server.exe", Drive & "BackedFiles\Server\Server.exe", overwrite:=True)
My.Computer.FileSystem.CopyDirectory(svr & "\world\", Drive & "BackedFiles\Server\Wolrd", overwrite:=True)



Right now it's piping the files being backed up to the textbox called "output" but it all happens really fast and it shows them 1 at a time. I was wanting it to place each file backed up on a new line. So that it looks like this;

banned-ips.txt
banned-players.txt
ops.txt
server.log
server.properties
white-list.txt
server.exe


all of them in the output text box. Try not to critique my code too much, as I said I'm a beginner.

More about : net beginner

Best solution

a b L Programming
April 15, 2012 6:13:09 AM

output.Text = Path.GetFileName(filenames(i))

This line re-assigns the Text property with a new value. What you want to do is append it using the += operator. You will also want to add a newline character after each filename else you'll just end up with one long string. The Environment.Newline constant will be the most cross-platform, but simply adding "\r\n" will work on Windows.

I know that you don't want too much critique, but I'd consider adding in some basic checks to see if certain required files actually exist before trying to read them :)  You'll get a FileNotFoundException when trying to open them if they don't.
Share
April 15, 2012 8:48:27 PM

Best answer selected by sodacycle.
m
0
l
Related resources
April 15, 2012 8:53:05 PM

randomizer said:
output.Text = Path.GetFileName(filenames(i))

This line re-assigns the Text property with a new value. What you want to do is append it using the += operator. You will also want to add a newline character after each filename else you'll just end up with one long string. The Environment.Newline constant will be the most cross-platform, but simply adding "\r\n" will work on Windows.

I know that you don't want too much critique, but I'd consider adding in some basic checks to see if certain required files actually exist before trying to read them :)  You'll get a FileNotFoundException when trying to open them if they don't.



Well in order to get to the form that this is on the user must select the Folder that these files are in, since it can be placed anywhere, using the "open folder dialog" window. That location is saved to the Test.Config file using the FileSystem.WriteAllText command and then changes some Booleans from false to true. So in order for the user to launch the form that has the backup button they must have selected the folder, thus changing the Booleans. I have it in a try... catch statement to make sure.
Thanks for the info on the text output though.
m
0
l
a b L Programming
April 16, 2012 10:24:30 AM

Ah, well that makes a bit more sense. Good luck :) 
m
0
l
!