What I am trying to figure out is how to display a progress bar when im performing a large task. This task will consist of reading records from a database, writing them to a text file, manipulating the data to write to a database and then present them on the screen. There can be several thousand records that I have to manipulate. I am having trouble getting a progressbar to accuratly display the progress. My problem seems to be that since i cant determine exactly how many records and how much time it will take that I cant accuratly update the progressbar. Any help is appreciated. Thanks
Problem related to progressbar control
Collapse
X
-
If you don't know how many records, then how are you able to go through them all? You either know how many at *some* point or you don't. If you don't know how many you are working with then not only could you not accurately produce a progress bar, but you wouldn't be able to ensure you are handling them all.My problem seems to be that since i cant determine exactly how many records -
When you read from the Database you will know the number of records that you are manipulating.
Set the progress bar's Maximum property to this number.....
VB code example:
Code:Dim totalNumberOfRecords As Integer 'This number is set when you retrieve the records from the database Private Sub CopyWithProgress(ByVal ParamArray filenames As String()) ' Display the ProgressBar control. pBar1.Visible = True ' Set Minimum to 1 to represent the first file being copied. pBar1.Minimum = 1 ' Set Maximum to the total number of records pBar1.Maximum = totalNumberOfRecords ' Set the initial value of the ProgressBar. pBar1.Value = 1 ' Set the Step property to a value of 1 to represent each file being copied. pBar1.Step = 1 ' Loop through all files to copy. Dim x As Integer for x = 1 To totalNumberOfRecords - 1 'Do Stuff....Then 'Perform the increment on the ProgressBar. pBar1.PerformStep() Next x End Sub
C# code:
Code:Integer totalNumberOfRecords // This number is set when you retrieve the records from the database private void CopyWithProgress(string[] filenames) { // Display the ProgressBar control. pBar1.Visible = true; // Set Minimum to 1 to represent the first file being copied. pBar1.Minimum = 1; // Set Maximum to the total number records. pBar1.Maximum =totalNumberOfRecords ; // Set the initial value of the ProgressBar. pBar1.Value = 1; // Set the Step property to a value of 1 to represent each file being copied. pBar1.Step = 1; // Loop through all files to copy. for (int x = 1; x <= totalNumberOfRecords; x++) { //Do Stuff...Then: // Perform the increment on the ProgressBar. pBar1.PerformStep(); } }Comment
Comment