hi,
I have a form and a button on that form.When the user clicks on the button an MS-Excel sheet is generated from MS-Sql Server 2005 and saved in a particular location.As this generation of excel tkes sometime to complete,what i want to do is i want to show a progressbar loading till the entire sheet is generated.
Showing the progress bar will help the user to understand that the generating of excel is under process.

Below My code to Save the File
ExcelWorkSheetObject.SaveAs(ExcelSheetName)
Below My Progressbar Code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ProgressBar1.Minimum = 0
        ProgressBar1.Maximum = 10
        ProgressBar1.Step = 1
End Sub
 
Button1_Click()
ProgressBar1.PerformStep()
Sub

I cant set the Maximum property of the progress bar as the size of the excel sheet can vary.
What i want is till the excel sheet gets compelety generated the progress bar should be displayed.
To save the excel file it takes a prety long time.
Please guide where and how should i use the Progressbar to solve my issue

in ExcelWorkSheetObject.SaveAs(ExcelSheetName) method perorm the step.
After saving all the data make ProgressBar1.Maximum = 100.

hi PG,
When i give the Step in the method its accepting the parameter but giving me error while Runtime.
Exception from HRESULT: 0x800A03EC is the Error im getting.
ExcelWorkSheetObject.SaveAs(ExcelSheetName, ProgressBar1.Step = 1)
I have not created anyother method to save the file rather im using the in-Built method to save the Excel-i.e(WorkSheetobject.SaveAs)

The best approach would be to create a new Thread (or using Backgroundworker - which is almost the same as creating new thread), and put the time consuming code (in your case this is work with database and generating excel file from the data), and put the progressBar on the UI thread. Dont forget to use Delegated to "update" or invoke the control on UI thread to be updated appropriatelly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.