Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. What do u want to say! [modifed]

What do u want to say! [modifed]

Scheduled Pinned Locked Moved Visual Basic
questioncomdiscussion
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    codeadair
    wrote on last edited by
    #1

    I write a code as follow to detect the timer event(System.timers.timer). timer1.interval=100 timer1.AutoReset=Ture timer1.enable=false 'My test code Imports vb = Microsoft.VisualBasic 'above all codes Dim startime As Single Dim sresult() As Single = New Single(10000) {} 'record each start time Dim i As Integer Dim j As Integer Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed sresult(i) = vb.Timer i += 1 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Timer1.Enabled = False End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click j += 1 TextBox3.Text = sresult(j) - sresult(j - 1) End Sub OK! What do u think it will be in textbox3?(After the second click) Wait for a minute to go on pls.Just say what do you think the answer now. OK! Come on,Everybody.Have you done it in your project? What is the result? And What i can see is: The number 0.09375 and 0.109375 displays alternatly. Why isn't it always 0.1 ? What is the number 0.09375 or 0.109375? And when i set timer1.interval=10 the alternate number is :"0" and 0.015625 Thank you for all ICQ:258-235-734 MSN:msnadair@hotmail.com -- modified at 5:03 Saturday 20th May, 2006

    M C 2 Replies Last reply
    0
    • C codeadair

      I write a code as follow to detect the timer event(System.timers.timer). timer1.interval=100 timer1.AutoReset=Ture timer1.enable=false 'My test code Imports vb = Microsoft.VisualBasic 'above all codes Dim startime As Single Dim sresult() As Single = New Single(10000) {} 'record each start time Dim i As Integer Dim j As Integer Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed sresult(i) = vb.Timer i += 1 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Timer1.Enabled = False End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click j += 1 TextBox3.Text = sresult(j) - sresult(j - 1) End Sub OK! What do u think it will be in textbox3?(After the second click) Wait for a minute to go on pls.Just say what do you think the answer now. OK! Come on,Everybody.Have you done it in your project? What is the result? And What i can see is: The number 0.09375 and 0.109375 displays alternatly. Why isn't it always 0.1 ? What is the number 0.09375 or 0.109375? And when i set timer1.interval=10 the alternate number is :"0" and 0.015625 Thank you for all ICQ:258-235-734 MSN:msnadair@hotmail.com -- modified at 5:03 Saturday 20th May, 2006

      M Offline
      M Offline
      MohammadAmiry
      wrote on last edited by
      #2

      Timer control (and Timer API) are not exact when are set to operate in small fractions of second... This just gives a relatively period near the interval you set. It is also affected by cpu usage... If you exactly want a sharp timer (for example if you are writing a media player program, to match audio and video you need it), search internet for High Resolution Timer. If you run a media player while you are testing your timer program, you get more accurate results (this is not an experience of mine, but one of my friends once had tested...)

      C 1 Reply Last reply
      0
      • C codeadair

        I write a code as follow to detect the timer event(System.timers.timer). timer1.interval=100 timer1.AutoReset=Ture timer1.enable=false 'My test code Imports vb = Microsoft.VisualBasic 'above all codes Dim startime As Single Dim sresult() As Single = New Single(10000) {} 'record each start time Dim i As Integer Dim j As Integer Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed sresult(i) = vb.Timer i += 1 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Timer1.Enabled = False End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click j += 1 TextBox3.Text = sresult(j) - sresult(j - 1) End Sub OK! What do u think it will be in textbox3?(After the second click) Wait for a minute to go on pls.Just say what do you think the answer now. OK! Come on,Everybody.Have you done it in your project? What is the result? And What i can see is: The number 0.09375 and 0.109375 displays alternatly. Why isn't it always 0.1 ? What is the number 0.09375 or 0.109375? And when i set timer1.interval=10 the alternate number is :"0" and 0.015625 Thank you for all ICQ:258-235-734 MSN:msnadair@hotmail.com -- modified at 5:03 Saturday 20th May, 2006

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        codeadair wrote:

        OK! What do u think it will be in textbox3?(After the second click) Wait for a minute to go on pls.Just say what do you think the answer now.

        Based on a timer interval of 100 ms I would expect the answer to be around about 0.1 If it is exactly 0.1 then you got lucky.

        codeadair wrote:

        OK! Come on,Everybody.Have you done it in your project? What is the result?

        I've used timers in projects before. I also read the documentation on them first which said that they are not exact.


        "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

        1 Reply Last reply
        0
        • M MohammadAmiry

          Timer control (and Timer API) are not exact when are set to operate in small fractions of second... This just gives a relatively period near the interval you set. It is also affected by cpu usage... If you exactly want a sharp timer (for example if you are writing a media player program, to match audio and video you need it), search internet for High Resolution Timer. If you run a media player while you are testing your timer program, you get more accurate results (this is not an experience of mine, but one of my friends once had tested...)

          C Offline
          C Offline
          codeadair
          wrote on last edited by
          #4

          Don't you think it is very interesting? It displays the two numbers alternantly every time when you run the program.

          MohammadAmiry wrote:

          Timer control (and Timer API) are not exact when are set to operate in small fractions of second... This just gives a relatively period near the interval you set

          As you say,It may be 0.1 more or less Instead of regular alternate number 0.09375 and 0.109375. ICQ:258-235-734 MSN:msnadair@hotmail.com

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups