Solved

Changing Label Text at Runtime

Posted on 2004-10-12
10
455 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 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
Industry Leaders: 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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 …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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