?
Solved

clearing a label/textbox after a specific time

Posted on 2001-06-25
8
Medium Priority
?
159 Views
Last Modified: 2010-05-02
Hi, I would like to ask for a simple way to do the following task:

By clicking a command button, a message will be shown in a label, and after a specific time, say 5 sec, the label has to be cleared.

Can I do that without using timer control?  I'd like to see if there's any statement in VB like:

label1.caption = 'my message'
wait 5 sec
label1.caption = ''

Thanks a lot!!
0
Comment
Question by:chuyan
[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
8 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6226320
Hi, you can use the GetTickCount API to do this:

put a StartTime on Form_Load()

Then in your Form_Activate(), Do a loop to compare the CurrentTime with the StartTime, if (CurrentTime - StartTime)/ 1000 > 5 then Clear the label1.caption.

'Hope will help.
'Code provided if necessary.

0
 

Author Comment

by:chuyan
ID: 6226404
Thanks for help.  I would like to see the code too.

But I want to ask, will it use up much CPU time as it continuously doing looping?
0
 
LVL 6

Accepted Solution

by:
sharmon earned 200 total points
ID: 6226427
You can do this as well...., I disabled the command button, you can handle it however you want though.

Private Sub Command1_Click()
  Command1.Enabled = False
 
  Label1.Caption = "My Message"
 
  Dim dteEnd As Date
 
  dteEnd = DateAdd("s", 5, Now())
 
  Do While Now() <= dteEnd
    DoEvents
  Loop
 
  Label1.Caption = ""
 
  Command1.Enabled = True
End Sub
0
Independent Software Vendors: 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 6

Expert Comment

by:sharmon
ID: 6226432
If you want to use the GetTickCount you could do this...


Option Explicit

Private Declare Function GetTickCount Lib "kernel32" () As Long


Private Sub Command1_Click()
  Command1.Enabled = False
 
  Label1.Caption = "My Message"
 
  Dim lngTickCount As Long
  lngTickCount = GetTickCount() + 5000
 
  Do While GetTickCount() <= lngTickCount
    DoEvents
  Loop
 
  Label1.Caption = ""
 
  Command1.Enabled = True
End Sub
0
 

Author Comment

by:chuyan
ID: 6226477
Thanks sharmon, your solution sounds simpler.

0
 
LVL 1

Expert Comment

by:vim_asteya
ID: 6226479
why dont u try the timer control
0
 

Author Comment

by:chuyan
ID: 6229765
vim_asteya, it's because it don't know how to fire the timer event after a specific time.
0
 

Author Comment

by:chuyan
ID: 6229798
oh... I just found I always had the wrong concept!  I just thought the timer event will fire whenever I enable the timer control!!  Thanks vim_asteya.  Using a timer control should be more simple.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

765 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