VB.NET Update Labels and Progressbars on forms

I am a veteran vb6 programmer finally upgrading...

In the old days if I was in a module and needed to update a status label or progress bar, i just called it via:

frmmain.progressbar1.value = newvalue
frmmain.label1.caption = "NEW LABEL"

How do I do it this easily in the new world?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It is still that easy. All form controls are declared as Friend, so your module should be in the same assembly as your form so that the module has access. Also, you will need to have an object reference to the instance of the form you wish to change. This is some example code:

Module Module1
    Dim frm1 As New Form1
    Public Sub main()
        frm1.Button1.Text = "This text was changed with a module"
    End Sub
End Module

To finish the above sample code,
* assuming Form1 has a progress bar called pb
* assuming StatusBar is called sb
* assuming StatusBar (sb) contains two panels called p1 and p2

Public Sub Whatever()
    frm1.pb.Incriment() 'Increments the progress bar by 1
    frm1.pb.Incriment(12) 'Incriment the progress bar by 12
    frm1.pb.Value = 50 'Set the progress to 50, wherever that happens to be between pb.minimum and pb.maximum
    p1.text = "New Text"
    p2.text = "More new text"
End Sub
OK, misread that, 2 corrections:
Two lines:
    p1.text = "New Text"
    p2.text = "More new text"
Should Read:
    frm1.p1.text = "New Text"
    frm1.p2.text = "More new text"

For a label:
* assuming Form1 contains lable called lbl1
   frm1.lbl1.text = "New Text"
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

jimtxasAuthor Commented:
great!  i was missing the declaration of the object reference.  I figured it would be something simple....

I've increased to 500, can you now tell me how to do the old fashioned form.refresh, label.refresh, etc and get the form to respond to these refreshes... seems like I saw something different somewhere than just using the refresh call...  What's the DoEvents call?
The correct call to make is invalidate(), this forces repainting.

Normally, you shouldn't need to do this in .NET...  What R U trying to do?  Be back tommorrow! G-night!
I assume you mean Application.DoEvents... The official explaination is this:

When you run a Windows Form, it creates the new form, which then waits for events to handle. Each time the form handles an event, it processes all the code associated with that event. All other events wait in the queue. While your code handles the event, your application does not respond. For example, the window does not repaint if another window is dragged on top.

If you call DoEvents in your code, your application can handle the other events. For example, if you have a form that adds data to a ListBox and add DoEvents to your code, your form repaints when another window is dragged over it. If you remove DoEvents from your code, your form will not repaint until the click event handler of the button is finished executing.

The most common use of Application.DoEvents is when you are in a subroutine that takes some time to complete, and you want to make sure that your program does not stay unresponsive (can't move forms, click buttons etc) while the code completes.

As for your .refresh() question, I agree with Lacutah, what is your goal with that?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
What I do, is I declare some public variables in a module as like:

Public Main as Form

and assign them to the forms as they are loaded. Then you just call:

Main.TextBox.text = "Clicky me here"

Also, the DoEvents has been changed. It is now practically the same as the System.Threading.Thread.Sleep(0) command. Seems like a lot, but if you import System.Threading, you just have to call Thread.Sleep(0):

Imports System.Threading

Public Sub DoEvents()


End Sub

This is better suited for new, .Net applications. It is also compatible for Multi-threading.

Yes, the correct way to repaint a control is Object.Invalidate()
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.