|
-
Jun 17th, 2008, 03:41 AM
#1
Thread Starter
Member
About timer
I'm using VB 2008 and i'm a newby.
Anyone out there know how to get the time between keystrokes?
For example, i type 'happy' and i want to calculate the time gap between the key i stroked, h-a, a-p, p-p, p-y .
is it we need to use timer?how?
thanks!
-
Jun 17th, 2008, 03:49 AM
#2
Re: About timer
Welcome to the Forums.
You can use the Stopwatch class to measure elapsed time in miliseconds.
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim st As Stopwatch = Stopwatch.StartNew()
'Do something
Threading.Thread.Sleep(500)
MessageBox.Show(st.ElapsedMilliseconds.ToString)
End Sub
End Class
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 17th, 2008, 03:52 AM
#3
Thread Starter
Member
-
Jun 17th, 2008, 05:01 AM
#4
Re: About timer
I have to ask.. If the stopwatch is on the same thread as your application, and you sleep the thread in your example, won't the value shown be pretty much 0?
-
Jun 17th, 2008, 05:40 AM
#5
Hyperactive Member
Re: About timer
nope
-
Jun 17th, 2008, 11:19 AM
#6
Re: About timer
Hmm.. that is interesting.. But I suppose if the stopwatch simply stores its first value and then checks the system clock and calculates the difference to get the timeelapsed, it makes sense. heh.
-
Jun 17th, 2008, 11:29 AM
#7
Re: About timer
 Originally Posted by MaximilianMayrhofer
Hmm.. that is interesting.. But I suppose if the stopwatch simply stores its first value and then checks the system clock and calculates the difference to get the timeelapsed, it makes sense. heh.
Thats exactly what it does
-
Jun 17th, 2008, 11:34 AM
#8
Re: About timer
I'm still a major newb haha.
-
Jun 17th, 2008, 11:56 AM
#9
Thread Starter
Member
Re: About timer
Urmm, the code given is for the stopwatch to run right?
Anyone know how we can start/stop the stopwatch by typing a single key in somewhere like a textbox?
-
Jun 17th, 2008, 12:09 PM
#10
Hyperactive Member
Re: About timer
maybe in the, keydown/keypress/keyup or textchange event of the textbox...
you could declare a list of string and the stopwatch
vb Code:
Dim test As New Stopwatch
Dim times As New List(Of String)
then in the textbox1_textchange event put this
vb Code:
If times.Count = 0 Then
test.Start()
times.Add(test.ElapsedMilliseconds & " (" & TextBox1.Text & ")")
Else
times.Add(test.ElapsedMilliseconds & " (" & TextBox1.Text.Substring(TextBox1.Text.Length - 2, 2) & ")")
test.Reset()
test.Start()
End If
to view the result do something like this..
vb Code:
For Each item As String In times
result += item & Environment.NewLine
Next
MessageBox.Show(result)
this is some fast and ugly code, but maybe you get the idea
-
Jun 17th, 2008, 01:53 PM
#11
Re: About timer
@rachelism, Read the documentation on the Stopwatch class. 
It also states that if you use StartNew it initializes it and resets all values whereas .Start will attempt to restart any already initialized instances and if none found it will start it.
There are alot more features to read about and will help you take advantage of the calss as you need.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 18th, 2008, 07:06 AM
#12
Thread Starter
Member
Re: About timer
thanks for the help..
so i used key-down and key-up method to determine the time of a key being pressed. it was successful 
now, i wish to determine the time interval between two key press.
i guess we have to use 'keypress'. i had read the keypress event but still not sure how to do it. anyone have idea how to do it?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|