Quantcast

Maximum PC

It is currently Sat Sep 20, 2014 7:31 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Updating text within a loop
PostPosted: Fri Nov 05, 2004 12:18 pm 
Professional Dork
Professional Dork
User avatar

Joined: Tue May 25, 2004 12:44 pm
Posts: 1246
Location: Cornhole County
I'm writing a little proggy that will countdown the time I have left in my job

Without going into the gory details, I have the following snippet of code to give you an idea of what it's like:

Code:
Do
    If <<condition>>
        Exit Do
    End If
    lblTimeToGo.Text = datNowTime.Second
    Thread.Sleep(1000)
Loop


The thing is that the label.text never get updated for whatever reason, I assume it's because the app is busy sleeping and processing data.

How can I have the gui change the text on the screen automatically? Another type of loop? Shelling out the sleep command? Other methods?

This is VB.NET, fyi


Top
  Profile  
 
 Post subject:
PostPosted: Fri Nov 05, 2004 4:12 pm 
Team Member Top 100
Team Member Top 100

Joined: Fri Sep 17, 2004 5:35 pm
Posts: 1176
Did you test if the part outside the condition is ever executed? Try a MessageBox there saying, "yo." or something to let you know if it's executed.


Top
  Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2004 6:00 am 
Professional Dork
Professional Dork
User avatar

Joined: Tue May 25, 2004 12:44 pm
Posts: 1246
Location: Cornhole County
I can step through and see the code updating the datNowTime.Second value


Top
  Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2004 7:30 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24224
Location: Granite Heaven
Warning: I know nothing about VB.net

Could the problem having anything to do with the fact that you are assigning an integer value (datNowTime.Second) to a character or string (lblTimeToGo.Text) ? Does VB.net handle these kinds of implied conversions?

I would try testing lblTimeToGo.Text = datNowTime.Second outside of the loop, to see if the assignment works.

Worth a shot, anyway. :)


Top
  Profile  
 
 Post subject:
PostPosted: Sun Nov 07, 2004 8:13 am 
Professional Dork
Professional Dork
User avatar

Joined: Tue May 25, 2004 12:44 pm
Posts: 1246
Location: Cornhole County
Jipstyle wrote:
I would try testing lblTimeToGo.Text = datNowTime.Second outside of the loop, to see if the assignment works.


Without the look code, it works just fine, it just never updates :)

Edit: THis is because Option Strict is off, meaning you can change data types from one to the other. Yes this is dangerous, which is why it's recommended you turn it on (why it's not by default is beyond me). In that case, then you'd get around this problem with the Cstr() command which can convert a numeric data type to string.


Top
  Profile  
 
 Post subject:
PostPosted: Sun Nov 07, 2004 11:51 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
I'm not familiar with VB, but here is how a simple second clock in Java works:
Code:
while (true)
  l.setText( new Date().toString() );
  Thread.sleep(1000);
}

Notice how I create a new Date object every 1000ms (a Date is an instant in time; whereas a Calendar represents multiple dates/times/etc). Do you need to do something similiar in VB? Just a shot in the dark...


Top
  Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 7:03 am 
Professional Dork
Professional Dork
User avatar

Joined: Tue May 25, 2004 12:44 pm
Posts: 1246
Location: Cornhole County
Once again, I find out that it's far easier than I ever imagined.

Add a timer object from Windows Forms, and set it to enabled with a tick event set to once a second, and then run everything out of a Timer_tick subroutine.

It automatically updates itself.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 4:51 pm 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24224
Location: Granite Heaven
Woo! Good to know you solved the problem. :)


Top
  Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 6:17 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000

Joined: Mon Jun 14, 2004 2:50 pm
Posts: 45
Location: Rochester, NY
HK-47 wrote:
Once again, I find out that it's far easier than I ever imagined.

Add a timer object from Windows Forms, and set it to enabled with a tick event set to once a second, and then run everything out of a Timer_tick subroutine.

It automatically updates itself.


MS offers something similar as an example.

http://msdn.microsoft.com/library/defau ... otimer.asp

(Got to this one late, I know.)


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group