[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Changing Label Text at Runtime

Posted on 2004-10-12
10
Medium Priority
?
463 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

834 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