[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

clearing a label/textbox after a specific time

Posted on 2001-06-25
8
Medium Priority
?
163 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

650 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