using delay in vb.net

A

AmitTrehan

hi friends,
I want to know how can we insert delay in vb.net
like.....
i want to show two strings on same label
first one string then break of 5 secs and then second string
how can i acheive this?
i mean label should show first
label.text("before")
then it should wait for 5 secs and then it should show
label.text("After")

thanks
Amit
 
A

Armin Zingler

AmitTrehan said:
hi friends,
I want to know how can we insert delay in vb.net
like.....
i want to show two strings on same label
first one string then break of 5 secs and then second string
how can i acheive this?
i mean label should show first
label.text("before")
then it should wait for 5 secs and then it should show
label.text("After")

label.text = "before"
system.threading.thread.sleep(5000)
label.text = "after"

Note that the app is locked during the 5 sec. If you don't want this, you
can use a Timer (see System.Windows.Forms.Timer) instead. After setting the
label the first time, enable the timer (interval = 5000). In the Timer's
Tick event, disable the timer and set the label text again.
 
C

Cor

Hi Amit,

Have a look at timer,
there are 3 can use the most simple for this the forms.form.timer

Although if you do not mind that your form freze you can also do
Roughly written here in this message
\\\
dim a as string() = {"Before","Middle","After"}
for i as integer = 0 to a.lenght - 1
label1.text = a(i)
threading.thread.sleep(5000)
next
///
I hope this helps

Cor
 
C

Cor

Hi Armin,

I think I get comments from Armin with my solution,

"Why not using a timer?

are you making the same

:)

Cor
 
H

Herfried K. Wagner [MVP]

* "Cor said:
Have a look at timer,
there are 3 can use the most simple for this the forms.form.timer

Although if you do not mind that your form freze you can also do
Roughly written here in this message

You can make a loop looping from 1 to 5 and let the thread sleep for 1
second, then call 'Application.DoEvents'. Quick and dirty, I know.
 
C

Cor

Hi Herfried,

That is my own solution in past often told not to be good by you

:) again the whole day gone?

Cor
 
A

AmitTrehan

Hi Amrin can't we have more genearl one that can show about 100 strings on a
specified gap

Thanks
Amit
 
A

Armin Zingler

AmitTrehan said:
Hi Amrin can't we have more genearl one that can show about 100
strings on a specified gap

At class level, store the information on what string to show next. In the
Timer's Tick event:
1. Use the information to show the string.
2. Change the information (an Index in a string array? Depends on your
needs) in order to show the right string next time. For example, increment
the index.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top