Results 1 to 15 of 15

Thread: Label.Text not displaying changes

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    34

    Label.Text not displaying changes

    Okay, so this is a weird problem and I simply can't figure out what I'm doing wrong. I have a timer that fires regularly that updates that label.text of a label on my main form. The timer fires correctly, the sub for changing the label runs. I can even go into debug mode and highlight the label.text in my code and it shows the correct string but the text in the form doesn't actually update.

    I've checked, double-checked and checked again that the names of the label in the form is correct and that I'm not doing anything obscenely stupid.

    I have some multithreading going and a D3D9 loop going as well, could these be interefering?

    Any ideas? I'm stumped.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: Label.Text not displaying changes

    after changing the label.text use:

    vb Code:
    1. application.doevents

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    34

    Re: Label.Text not displaying changes

    Tried that, it didn't work =\

  4. #4
    Addicted Member
    Join Date
    Dec 2006
    Location
    London, England
    Posts
    142

    Re: Label.Text not displaying changes

    you could also try a form refresh

    at the end of the sub that updates the label, try

    dim myform as new frmMain

    myform.refresh()

    Redmo
    The universal aptitude for ineptitude makes any human accomplishment an incredible miracle -Col. John P. Stapp


    Please rate the posts that have helped. Makes us feel all warm and fuzzy

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: Label.Text not displaying changes

    you'll have to post your code.
    it sounds like you have several threads running at the same time.
    using application.doevents in the right place will probably free up your UI + you'll see your label updates.

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    34

    Re: Label.Text not displaying changes

    http://newtons.bit.googlepages.com/Game10-30-08.zip

    Here's the source code. If anyone wants to take a look I'd greatly appreciate it. I put a break at the sub that calls that label change event.

    It does require the DirectX SDK Aug 08.

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    34

    Re: Label.Text not displaying changes

    Anybody? Anybody? Bueller?

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Label.Text not displaying changes

    paste the code you are having trouble with.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Label.Text not displaying changes

    But first, have you tried Me.Refresh?
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    34

    Re: Label.Text not displaying changes

    I've tried Me.Refresh and Application.DoEvents. No luck. The code is just:

    Code:
    Public Sub UpdateGameDate(ByVal sString As String)
    lGameDate.Text = sString
    It doesn't actually update the label. However when I go into debug mode and highlight lGameDate.Text it shows a value different than what is displayed on the form (and what it should correctly be incidently). The source code of the project is posted above.
    My journey of being a new game developer:
    http://neogamedev.blogspot.com/

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Label.Text not displaying changes

    Is that sub called only from the UI thread?

    The only remaining possibility that seems even remotely possible...and the more I think about it, the less I actually like it, is that the wrong form is being updated.

    Other than that, is there anything ELSE happening on that form? Can you make any other change to determine whether it is just this label, or if nothing about the form is being updated?
    My usual boring signature: Nothing

  12. #12

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    34

    Re: Label.Text not displaying changes

    Quote Originally Posted by Shaggy Hiker
    Is that sub called only from the UI thread?

    The only remaining possibility that seems even remotely possible...and the more I think about it, the less I actually like it, is that the wrong form is being updated.

    Other than that, is there anything ELSE happening on that form? Can you make any other change to determine whether it is just this label, or if nothing about the form is being updated?
    I do know that the form is showing updates. I have another label on the form that tells me what the keycode of a button I press is (basically just a debug thing). The sub that updates the gamedate label is being called from a different thread than the UI thread.

    The form that all of this is occuring on is the startup form and isn't an instance I create. Could that be part of the problem?
    My journey of being a new game developer:
    http://neogamedev.blogspot.com/

  13. #13
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Label.Text not displaying changes

    Yeah, the problem lies in those statements. You shouldn't even be able to alter a control from any thread other than the UI thread. You should have received an IllegalCrossThreading exception when you tried to do so. If you didn't, then why not?

    If you didn't create an instance of the startup form....that should be fine.
    My usual boring signature: Nothing

  14. #14
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Label.Text not displaying changes

    "I have a timer that fires regularly that updates that label.text of a label on my main form. The timer fires correctly, the sub for changing the label runs."

    lets see your code for the timer and the sub for changing the label.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  15. #15

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    34

    Re: Label.Text not displaying changes

    Quote Originally Posted by Shaggy Hiker
    Yeah, the problem lies in those statements. You shouldn't even be able to alter a control from any thread other than the UI thread. You should have received an IllegalCrossThreading exception when you tried to do so. If you didn't, then why not?

    If you didn't create an instance of the startup form....that should be fine.
    Yea, I didn't get that exception. The weird thing, is that I was getting this same problem before I started multithreaded the program. I can step through the program and watch the timer fire, watch the sub get killed to change the text of the label, highlight the text of the label that shows (correctly) what the text should be. It just doesn't show up in the form.
    My journey of being a new game developer:
    http://neogamedev.blogspot.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width