|
-
Jul 17th, 2004, 09:52 AM
#1
Thread Starter
New Member
Delay
how can I insert a small (1 sec ) delay between 2 numbers being displayed in 2 textbox's.
i.e a number is shown in textbox1 then 1 second later a second number is shown in textbox2
I have the numbers appearing in the right boxes but instantly
p.s
I am a begginer at VB
Thanks Trevor
-
Jul 17th, 2004, 10:48 AM
#2
PowerPoster
Hi,
Put the following immediately after the code which reveals the first number.
VB Code:
Dim Present as datetime=now
do
if now>present.addmilliseconds(1000) then exit do
Loop
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 17th, 2004, 10:48 AM
#3
Frenzied Member
VB Code:
System.Threading.Thread.Sleep(1000)
Try searching the forum first before you post - this question has been asked many times.
Mike
-
Jul 17th, 2004, 02:50 PM
#4
PowerPoster
Originally posted by Mike Hildner
VB Code:
System.Threading.Thread.Sleep(1000)
Mike
If you use Sleep then you have to update your object BEFORE it in the code stream.
E.G.
VB Code:
TextBox1.Text ="1"
TextBox1.Update ( or Me.Update if necessary)
System.Threading.Thread.Sleep(3000) (Halts thread for 3
seconds)
TextBox2.Text ="2"
Edited: Sleep(1000) to Sleep(3000) after prompting.
Last edited by taxes; Jul 17th, 2004 at 06:14 PM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 17th, 2004, 03:33 PM
#5
Frenzied Member
Yes you do. But it's still less typing , especially when you Import.
-
Jul 17th, 2004, 04:30 PM
#6
yay gay
Originally posted by taxes
If you use Sleep then you have to update your object BEFORE it in the code stream.
E.G.
VB Code:
TextBox1.Text ="1"
TextBox1.Update ( or Me.Update if necessary)
System.Threading.Thread.Sleep(1000) (Halts thread for 3
seconds)
TextBox2.Text ="2"
Halts thread for 3 seconds? It halts for 1
\m/  \m/
-
Jul 17th, 2004, 06:12 PM
#7
PowerPoster
Hi,
"Halts thread for 3 seconds? It halts for 1"
Sorry, my mistype. It shouldn't have taken him long to figure that out though
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 17th, 2004, 06:17 PM
#8
PowerPoster
Originally posted by Mike Hildner
Yes you do. But it's still less typing , especially when you Import.
But don't forget Sleep stops the entire thread so if other things are going on they are aslo delayed.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 17th, 2004, 10:25 PM
#9
Frenzied Member
why not just throw a for next loop between the lines of code that insert the values?
-
Jul 18th, 2004, 08:13 AM
#10
PowerPoster
Originally posted by Andy
why not just throw a for next loop between the lines of code that insert the values?
Do you REALLY mean that
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 18th, 2004, 09:39 AM
#11
Hyperactive Member
I know there are two easy ways to work with asyncronous events without multithreading. Timers and Application Idle.
Taxes's first solution seems very good if you avoid the heavy looping, so your app. can react for button clicks and so on. I have never applied it, only read something, but I think you can test system clock, as Taxes suggested, in Application Idle event. Repeat...I've never tried this way. It should be possible and convenient, but you have to verify directly. Good job!
Live long and prosper (Mr. Spock)
-
Jul 18th, 2004, 10:43 AM
#12
PowerPoster
Hi alextyx
do you mean something like
VB Code:
Dim Present as datetime=now
do
Application.DoEvents
if now>present.addmilliseconds(1000) then exit do
Loop
This will allow events occuring outside of the loop to be recognised, although it is hardly necessary in the case of a 1 second delay (except perhaps in a game.)
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 18th, 2004, 04:16 PM
#13
Hyperactive Member
Hi taxes. Your is a anyway a solution to process events like button clicks (that was my example!). Probably, at this level, yours is the best solution. I have thought that, but I wanted to propose something more. Problem is I'm speaking about something I've only read on a book and never applied. If I undestood well, there is an event (application idle) that occurs every not fixed intervals, but surely several times par second and you can use it to perform a test like yours, but as I said, your first solution, integrated with a simple Application.Doevents, seems very good!
And....I've not experimented if Application.Idle occurs also if a classic loop is processing. Timer can fail in this situation, but I have not found detail about what could happen on Application.Idle event. It occurs anyway, or not? I will test it....in the future!
Live long and prosper (Mr. Spock)
-
Jul 18th, 2004, 05:52 PM
#14
PowerPoster
HI alextyx,
Not quite sure what you mean. Thr Application.Idle event is fired each time the application is about to go into the idle state and you use it to contain code which must be accomplished before that happens. (Update of controls is an example). As far as I know, it is not fired "several times a second".
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 19th, 2004, 03:16 AM
#15
Hyperactive Member
Yes Taxes, it's possible you were right. As I said, I haven't tried it. In the example I found, the idle event was used to update time in the title of form (very close to our problem). It suggests that idle fires frequently (is specified, anyway, that are not fixed intervals for this), but it's not clear what happens when the thread of the form is working heavily. It's possible it stops. A Timer will work, but if you are in a loop, you need an application.doevents to permit it to fire. Probably you are asking why I'm worrying about this when you already gave solution. The reason is I'm thinking about my situation. I've a very very slow Notebook and clicking some buttons that fill listview from database, changing colors of subitem, calculating results, etc.. I put my PC in a task that requests many seconds. So I was thinking that could be better, for situation like this, to reverse our point of view: Let the form's code work normally and perform your code in an event routine (I thought Idle or Timer, probably only timer is good). So if you continue to work, also in a loop, like filling my listbox, you can also let your delay works and put your result in textbox after the specified time is elapsed. I think, one second is not a problem. We can use also a Sleep for thread, effectively, but I like your approach because it could be performed without stop the thread or drain all its resources. So, if tomorrow the delay will increase, we will not be in a situation of freezed code. Now a doubt.....was my english sufficiently good or none has understood anything?
Live long and prosper (Mr. Spock)
-
Jul 19th, 2004, 03:59 AM
#16
PowerPoster
Hi alextyx,
Yes your English is understood.
It looks like you just have to experiment with your LapTop. Best of luck.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 19th, 2004, 05:38 AM
#17
Hyperactive Member
Thanks Taxes
You are perfectly right on the idle event. I write the example application (by memory, but it's very short and easy) and I verified, as you said, it doesn't work properly. I can't imagine why it was proposed!
Timer works, as I knew. Anyway we are started from an easy and already solved question to a far and complicated discussion.
This is my test form's code. Form contains a Timer (300ms) and two buttons . As you can see, I use timer to refresh time, but you can easily adapt it to other use.
VB Code:
Dim flagstopciclo As Boolean = False
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'AddHandler Application.Idle, AddressOf Me.Orologio
Me.Timer1.Enabled = True
End Sub
Private Sub Orologio(ByVal sender As Object, ByVal e As System.EventArgs)
Me.Text = Now
End Sub
Private Sub BtnFine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFine.Click
Me.flagstopciclo = True
End Sub
Private Sub BtnParti_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnParti.Click
Do While Not Me.flagstopciclo
Application.DoEvents()
Loop
MessageBox.Show("Finito")
Me.flagstopciclo = False
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Orologio(Nothing, Nothing)
End Sub
P.S. I need not only to experiment ...I need to buy a new Notebook!!! (550Mhz 256Kram 12,1"LCD not TFT)
Live long and prosper (Mr. Spock)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|