Solved

clearing a label/textbox after a specific time

Posted on 2001-06-25
8
151 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 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 6

Expert Comment

by:sharmon
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:chuyan
Comment Utility
Thanks sharmon, your solution sounds simpler.

0
 
LVL 1

Expert Comment

by:vim_asteya
Comment Utility
why dont u try the timer control
0
 

Author Comment

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

Author Comment

by:chuyan
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now