473,387 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help me make a timer that logs.

Hi, I am new to vb and as a starter project, I want to make a timer that is activated/deactivated by pushing "F10" and as well as logs your time from the the time to activate to the time to deactivate and store it in a text document..

any help ?
Oct 4 '07 #1
7 1139
Killer42
8,435 Expert 8TB
Hi, I am new to vb and as a starter project, I want to make a timer that is activated/deactivated by pushing "F10" and as well as logs your time from the the time to activate to the time to deactivate and store it in a text document.
Our members and experts will be glad to help with specific questions along the way, but you really need to try and tackle the problem yourself.

One thought... use the Form's KeyPress event to detect F10 and toggle the Timer's Enabled property.
Oct 5 '07 #2
jamesd0142
469 256MB
Firstly work out what you need to do in english...

1. Create timer function.
2. Detect F10 keypress.
3. Use global variable, this will detect if the timer is running or not.
4. On F10 keypress start timer function, on f10 keypress stop time and store value in variable.
5. Open/create text file, store details.
6. Etc.

You see the idea.

Thanks
Oct 5 '07 #3
1. Create timer function
...
The idea of James really works well but do you think F10 key can be detected easily? It is easy to detect the alphanumeric keys but I don't know how to detect the function keys. Can you tell how to detect the following keys?
All function keys
Tab
Caps Lock
Scroll Lock
Num Lock
Home
Page Up
Page Down
End
Insert
Delete
all Arrow Keys
Print Screen
Ctrl
Alt
Esc
Shift
Oct 5 '07 #4
jamesd0142
469 256MB
This gives the difference between start and stop of timer1.
The ASCII code 13 is the Enter button.

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Public Class Form1
  3.     Dim oFile As System.IO.File
  4.     Dim oWrite As System.IO.StreamWriter
  5.     Dim timer As Integer = 0
  6.     Dim b As String
  7.     Dim c As String
  8.     Dim d As String
  9.     Dim ee As String
  10.     Dim ff As String
  11.  
  12.     Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
  13.         'Dim b As String = Keys.F10
  14.         Dim a As String = Asc(e.KeyChar)
  15.         If a = "13" Then
  16.             If timer = 0 Then
  17.                 b = System.DateTime.Now
  18.                 MsgBox("Start " + b)
  19.                 timer = 1
  20.  
  21.                 Exit Sub
  22.             End If
  23.  
  24.             If timer = 1 Then
  25.                 c = System.DateTime.Now
  26.                 MsgBox("Stop " + c)
  27.                 timer = 0
  28.                 'work out difference
  29.                 d = Mid(c, 12)
  30.                 ee = Mid(b, 12)
  31.  
  32.  
  33.                 ' get all no's
  34.                 Dim i As Integer
  35.                 Dim q As String
  36.                 Dim w As String
  37.                 Dim dd As String
  38.                 Dim eee As String
  39.                 For i = 1 To Len(d)
  40.                     q = Mid(d, i, 1)
  41.                     If q <> ":" Then
  42.                         dd = dd + q
  43.                     End If
  44.                 Next
  45.                 For i = 1 To Len(ee)
  46.                     w = Mid(ee, i, 1)
  47.                     If w <> ":" Then
  48.                         eee = eee + w
  49.                     End If
  50.                 Next
  51.  
  52.                 'store in d an ee
  53.                 MsgBox(dd)
  54.                 MsgBox(eee)
  55.                 ff = dd - eee
  56.                 MsgBox(ff) 'Gives the time between timer1 start and stop
  57.                 'write to file
  58.                 '--------------------
  59.                 Exit Sub
  60.             End If
  61.  
  62.  
  63.         End If
  64.  
  65.     End Sub
  66.  
  67. End Class
As for function keys, use the ASCII code for these eg... f10 = "121"
Oct 5 '07 #5
Killer42
8,435 Expert 8TB
...As for function keys, use the ASCII code for these eg... f10 = "121"
I think you'll find that there are named constants to represent the keys. In VB6 I think they're called things like vbKeyF10. Don't know about later versions.
Oct 5 '07 #6
jamesd0142
469 256MB
I think you'll find that there are named constants to represent the keys. In VB6 I think they're called things like vbKeyF10. Don't know about later versions.
yes ur correct but i ran into all types of problems with these cudn get them to work, its easier to use the ascii codes i found.
Oct 6 '07 #7
Killer42
8,435 Expert 8TB
yes ur correct but i ran into all types of problems with these cudn get them to work, its easier to use the ascii codes i found.
Fair enough, I suppose. If it works, that's more important than looking nice.
Oct 6 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: tym | last post by:
HELP!!! I'm going round the twist with this... I have a VB6 application which is using DAO to access a database (Please - no lectures on ADO, I know what I'm doing with DAO!!) Ok, problem...
2
by: MyNameIsnt | last post by:
Can anyone tell me why, when I click on the buttons it register 2 characters on the display? if you use the right mousebutton it works ok, but the buttons dont flash?? it works fine without the...
8
by: Chris | last post by:
Hi, I want to use a popup control in my asp app like the one in outlook web access and msn. This will be used to notify users of a change in the database. I plan on using the one on codeproject,...
8
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a...
2
by: John David Thornton | last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and I've coded it as shown below. However, when I install the service and then start it in MMC, I get a peculiar message: ...
11
by: Kevin Antel | last post by:
We have written a service that uses a timer control to check for a process every 60 seconds. This is installed on a Windows 2003 Server w/SP1. The problem we are running into is that the service...
3
by: Steve Lowe | last post by:
Hi, I'm getting into VB.net with the help of a few books, but have got a problem grasping how to implement a system.timers.timer Only 1 of my 3 books mentions timers and that's a...
11
by: Zilla | last post by:
I have the following simple program. I just want to be able to do math operations (+, -, =)on Timer sublcasses, but want to handle cases where either rhs or lhs is an intrinsic value, However, the...
8
by: Ollie Riches | last post by:
I'm looking into a production issue related to a windows service and System.Timers.Timer. The background is the windows service uses a System.Timers.Timer to periodically poll a directory location...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.