VB.net geeks in here please

Soldato
Joined
5 Aug 2006
Posts
4,261
Right im making a simple application for my mums laptop to backup her files and stuff.

Anyway, since im very new and no good at VB.net i opted for using FileSystemObject to do the work for me.

So bearing that in mind is it possible (from searching the net i suspect not) to link its progress to a progress bar?
 
Yes you can. I take it you will be using the FileSystemObject to move files from one location to another? If so then get a count of the number of files to be moved/copied. then set you progress bar maximun to the file count. After a file is moved/copied increase the progress bar values by 1.

TrUz
 
Here is a sample in C#. Obviously it is not VB but you should get the idea. And using System.IO instead of the FileSystemObject is much easier.
Code:
            int fileCount = Directory.GetFiles(@"C:\SomeFolder").Length;

            // Set progress bar maximum = fileCount
            foreach (string file in Directory.GetFiles(@"C:\SomeFolder"))
            {
                File.Copy(file, @"D:\BackupLocation");
                // ProgressBar.Value = ProgressBar.Value + 1
            }
TrUz
 
Here is a sample in C#. Obviously it is not VB but you should get the idea. And using System.IO instead of the FileSystemObject is much easier.

I was under the impression if you want to copy a folder structure reclusivly or however you spell it it was a bit more effort (which as you can see from doing it the way I've done it its only taken a few lines of code)

Yes you can. I take it you will be using the FileSystemObject to move files from one location to another? If so then get a count of the number of files to be moved/copied. then set you progress bar maximun to the file count. After a file is moved/copied increase the progress bar values by 1.

TrUz

Yes i will.

Im gonna look it up now but in case i cant work it out myself how/what fso method (or another way prehaps) will count the number of files ?

cheers dudes

alec
 
Some thing like this will to the trick I think. It has been along time since I have used FSO.
Code:
Dim fileCount as Integer = fso.GetFolder(Directory).Files.Count
TrUz
 
I've been scratching my head and trying, but I cant work it out so I'll have to ask.

How exactly would get the progress bar to relate to the files transferd. does not have to be accurate, so simply by working out how many files have been copied and still have to be will be enough.

Thank you for helping me out.
 
Truz answered it perfectly above. Just set the Progress bars maximum value to the file count, and then for each file transfered (after the FSO call), just increment the value of the progress bar by 1.
 
As said, count the number of files you plan to backup. Set the progress bar maximum to the file count e.g. myProgressBar.Maximum = 200. Then after you have made your fso call to move/copy said file set the progress bar value equal to the current progress bar value + 1 e.g. myProgressBar.Value = myProgressBar.Value + 1.

EDIT: The progress bar never relates to anything. You always have to increment it your self in someway. If you do not know the time or amount of something you might be better of setting the progress bar to marquee. This will cause the progress bar to just keep scrolling along like on Windows bootup.

TrUz
 
Last edited:
Grr, well it turns out i probably did have it working, but it turns out when do the fso copy the application is none responsive so once its in progress regardless of what i might do (for example change style of progress bar to marque) it wont actually happen until its done!

well thanks a million people - at least i know for future reference i suppose!



now on to my next job.. creating schedule tasks programmatically.. hmm lol
 
Grr, well it turns out i probably did have it working, but it turns out when do the fso copy the application is none responsive so once its in progress regardless of what i might do (for example change style of progress bar to marque) it wont actually happen until its done!

Multithreading is your friend :)

Always have any processor-intensive tasks running on separate threads from the UI.
 
Grr, well it turns out i probably did have it working, but it turns out when do the fso copy the application is none responsive so once its in progress regardless of what i might do (for example change style of progress bar to marque) it wont actually happen until its done!

You need to use a background worker so the work is not done on the same thread as the ui.

When using the background worker, you can use the reportprogress method to change the progress bar value. That or you could use cross-thread-calls.

This will keep the program "responsive" (as you call it).
 
Cool. Shall look into it, although im no longer using FSO method, using My.Computer.FileSystem.

I would have used that in the first place if i knew it exsisted! not as documented (it would appear) as some other ways of doing it!
 
Thanks again guys, Bearing in mind the other day was the first time i've ever propperly used VB.net so im still learning! quite fun actualy.

Project is currently sitting at 78 (how pathetic!) lines of code.

Looking very new and crude

http://homepage.ntlworld.com/frances.hewitt1/Pictures/SimpleBackup1.1.0.0.PNG

Still a long long way to go! :) but its a been fun learning!

Probably another 2 weeks before a releasable version is availble! not that anyone beside my mother will use it!


*edit*

please excuse my poor grammer, layout and spelling in that screenshot - its not gonna look pretty for a long time - just coding it atm
 
Back
Top Bottom