?
Solved

Changing Label Text at Runtime

Posted on 2004-10-12
10
Medium Priority
?
456 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

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
 
LVL 86

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 86

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

752 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