It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Visual Basic Express - Help Needed

Moderator: dafunkymunky

Visual Basic Express - Help Needed

Postby Rodney on Fri May 09, 2008 10:09 am

Hi All

I am trying to create a program that eventually will backup data, my biggest challenge is that the progress bar runs when "previewing".
I would like to add a button "start" and connect the progress bar to execute when "start" is clicked.
I also would like the cancell button to close the entire program... sigh*


Any input will be appreciated !! :idea:





Public Class Form1

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing


End Sub


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.BackgroundWorker1.RunWorkerAsync()

ProgressBar1.Style = ProgressBarStyle.Continuous = 10000

ProgressBar1.Dock = DockStyle.Bottom

ProgressBar1.Visible = True

ProgressBar1.Minimum = 1

ProgressBar1.Maximum = 100

BackgroundWorker1.WorkerReportsProgress = True

BackgroundWorker1.WorkerSupportsCancellation = True

End Sub


Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

Dim i As Integer = 0

While (Not Me.BackgroundWorker1.CancellationPending) And i <= 99

i = i + 1

System.Threading.Thread.Sleep(200)

Me.BackgroundWorker1.ReportProgress(i) ' file processing here

End While

If (Me.BackgroundWorker1.CancellationPending) Then

e.Cancel = True


Else

End If

e.Result = "BACKUP COMPLETED"


End Sub


Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged

ProgressBar1.Visible = True

ProgressBar1.Value = e.ProgressPercentage

End Sub

Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted

ProgressBar1.Visible = False

If (e.Error IsNot Nothing) Then

MessageBox.Show(e.Error.Message)

ElseIf e.Cancelled Then

MessageBox.Show("Canceled")

Else

End If

MessageBox.Show(e.Result.ToString)
If (e.Cancelled = True) Then

End If


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Me.BackgroundWorker1.CancelAsync()

End Sub
Rodney
 
Posts: 0
Joined: Fri May 09, 2008 9:56 am

Who is online

Users browsing this forum: No registered users and 2 guests