Solved

Changing Label Text at Runtime

Posted on 2004-10-12
10
414 Views
Last Modified: 2010-04-23
I am going nuts trying to figure this out.

All I want to do is when I click a button on my form (which executes a SQL query), change a label text on my form to read "Please wait while the query executes..."

I have:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     Me.Button1.Text = "Please wait while the query executes..."

     (Do SQL Stuff)
End Sub

The label is not changing.  I have tried to remove the default label text (which I would then set at Form Load) and this doesn't help.

Why do basic things need to be so hard sometimes???
0
Comment
Question by:ABaruh
  • 3
  • 3
  • 3
  • +1
10 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12289852
Works fine on my pc
 Me.Button1.Text = "Please wait while the query executes..."

After I click the button the Button text changes. Do you get any error?
0
 
LVL 2

Accepted Solution

by:
UncleMidriff earned 500 total points
ID: 12289867
I feel your pain.  I've lost count of the times I have pulled my hair out for hours on a simple problem.  

Try

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

      Me.Button1.Text = "Please wait while the query executes..."
      Me.Button1.Refresh

      (Do SQL Stuff)

End Sub

Also, I don't think you need to use Me.Button1.BlahWhatever.  Instead, try just Button1.BlahWhatever.

Hope that helps.
0
 
LVL 7

Author Comment

by:ABaruh
ID: 12289873
No....nothing happens

If I take out my SQL query it works fine.  Why is it not doing anything while processing the SQL query?  I am changing the label before the SQL
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12289886
Well, you are changing the Buttons text, not a Labels text.  Have your tried using the Label name in your code instead of the Button name?

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

     Me.Label1.Text = "Please wait while the query executes..."

     (Do SQL Stuff)
End Sub
0
 
LVL 7

Author Comment

by:ABaruh
ID: 12289903
Idle_Mind, good catch, I just typed that wrong in the example though
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12289924
You can force a refresh before jumping into the SQL code like this:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = "Please wait while the query executes..."
        Label1.Refresh()
        Application.DoEvents()

        '  (Do SQL Stuff)
    End Sub
0
 
LVL 7

Author Comment

by:ABaruh
ID: 12289966
Idle_Mind, I had already accepted Uncle's comment about the Refresh, thanks to everyone though.
0
 
LVL 2

Expert Comment

by:UncleMidriff
ID: 12290028
Thanks Aburah.

Idle_Mind:  Is the DoEvents necessary?  I just made a little test program for this program without the DoEvents and it worked, but now I am all curious as to what situations need a DoEvents.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12290201
It really depends on what else is going on in the application.

If you have other threads already running in the application then the Refesh() may get stuck in the message queue until those threads yield the processor or finish.

The DoEvents call forces the app to process any messages in it's queue.  Adding it in ensures the the Refesh() message will be processed NOW.  =)

If you don't have anything else going on in the app then it probably doesn't make a difference.

~IM
0
 
LVL 2

Expert Comment

by:UncleMidriff
ID: 12290604
Ahhh...ok, that makes sense.  Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now