Solved

clearing a label/textbox after a specific time

Posted on 2001-06-25
8
153 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
8 Comments
 
LVL 50

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 50 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

777 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