CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2012
    Posts
    3

    [Help] How to associate a timer to my function.. ?

    I am facing another issue. I want to associate a timer to my function. Actually what i am doing is that i am tryin to store certain values in a database. A function is such that it calculates 5 values and stores them in a database. While storing them in the database it displays them in a textbox on the form. Now i want to display them one by one which it does. But it does it so fast that i can only see the last value that it enters in the database inside the textbox.

    Can i make it show all the values slowly one by one.

    Can anybody suggest me how to do so. I googled a lot but could find a particular answer.
    thnx in advance friends..

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: [Help] How to associate a timer to my function.. ?

    A good solution greatly depends on your existing code.
    1. The easiest thing is to delay your loop by using the Sleep API to wait for a couple of milliseconds/seconds. But this has several disadvantages.
    2. You could use a timer control to create a wait-loop
    Code:
     'this is your loop
      ...
      txtDisplay.Text = NextValue
      Timer1.Enabled = True
      While Timer1.Enabled: DoEvents: Wend
      ...
    
    ' this is the code in the timer event:
     Private Sub Timer1_Timer()
       Timer1.enabled = False
     End Sub
    Depending on your coding, where these values you compute are stored and how long they are stored and in what scope they are stored, you could use the timer control in a different way, to display all values one by the other, while the program is continuing already.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



HTML5 Development Center

Click Here to Expand Forum to Full Width