I'm having some trouble with editing the .text property of a label control in a form from the main form.
Here is what I am trying to accomplish:
- User clicks start
- Another window with the progress bar opens up
As the program in the main form runs I the label text and progress updates with where the application is at and the % completed (the % completed is just a .Value and number I'm placing in)
Public Class frmMain Dim progress As frmProgress
Public Sub LoadProgress() InitializeComponent() progress = New frmProgress progress.Show() End Sub
Then I call the objects in the form I want with
progress.label.text = "stuff" progress.prgTaskProgress.Value = 25
This... technically works. However it seems to break the availability of the all of my main form variables and objects (like text boxes). For example I have an exception for if you leave one of the text boxes blank, well after the progress bar form is loaded it doesn't see the text box value, so thinks its blank and throws an error.
If I remove the InitiliazeComponent() call, I can still change the .Value of the progress bar, which really has always worked I was able to just use frmProgress.progTaskProgress.Value = 25 before and it would work.
Sorry got off topic, if I remove the initialize, I can still access the progress bar no problem, but the text values of my label no longer change and the rest of the application runs with no issues.
Now if I were just starting the application, I would probably have the tasks that run on the main form and move them to the progress bar form, however this is an additional / enhancement to an already nearly completed application so it would be troublesome to do this at this point.
Alternatively, I can just use a .visible and hide/show the progress bar on the main form as needed, but I'd rather have it as its own form.
I tend to ramble so I'll summarize: - The code above "works", but I lose access to the main form objects contents (like the text in a text box - If I remove InitializeComponent() I can still change the progress bar object and the running code can still access all the other main form objects, but the ability to change the .text value on the progress form is gone.
I hope I explained this properly that you can understand what I'm trying to do.
Update: I found trying some of your posted solutions that actually some of my statements DO work, but I never let them get that far before.
If My.Computer.FileSystem.FileExists(extFilePath + fileXP) Then fileXPNew = domainName + " " + fileXP My.Computer.FileSystem.RenameFile(extFilePath + fileXP, fileXPNew) My.Computer.FileSystem.CopyFile(extFilePath + fileXPNew, modSharePath + fileXPNew, True) ' FAIL progress.lblTaskName.Text = "Processing XP Migration Readiness Report" Thread.Sleep(15000) ' Pause for OneSync delay My.Computer.FileSystem.DeleteFile(extFilePath + fileXPNew) progress.prgTaskProgress.Value = 90 End If progress.lblTaskName.Text = "Transfer Complete. Closing Processes please wait..." Thread.Sleep(2000) progress.prgTaskProgress.Value = 93 Thread.Sleep(2000) progress.prgTaskProgress.Value = 96 Thread.Sleep(2000) progress.prgTaskProgress.Value = 99 Thread.Sleep(2000) progress.prgTaskProgress.Value = 100 ' WORKS progress.lblTaskName.Text = "Process Complete. Please verify your OneDrive sync. Resetting application..." Thread.Sleep(2000) progress.Close() Catch ex As Exception MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) End Try Catch ex As Exception MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try
I highlighted the lines that fail and work though the gray out on the website might be a little tough to see.
It's all in a TRY statement, the changes to the label text on the other form fail in the IF statements which are nested in a TRY statement, but not on the lines that are in the TRY by itself. I hope that makes sense?
I'm gonna get some sleep and hopefully I'll be able to make more sense tonight.