944,147 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Jan 22nd, 2005
0

Text Timer

Expand Post »
Hi there, nice to meet you all.

I'm a beginner using visual basic only started to learn it about a months ago. I'm having serious trouble at the moment.

I need a program that as soon as it is opened it prints the time into 100ths or miliseconds of seconds, then run the proram and then print the time again just as it ends. (timer at the moment only shows the Time as HH:MMS, i want it to show HH:MMS:Miliseconds if possible)

For example i open the program and the display on the timer label is prined into Text1 then it runs my loop 10000 times then as soon as it finishes the loop i it to print the time on the timer into Text2.

The reason im doing this is i need to investigate speeds of processors in different machines and prove that the faster the processor the quicker it can complete this loop. Timing by had is just not accurate enough.

all i have so far is:

Private Sub Form_Load()
Text1.Caption = time
for x = 1 to 10000
Print "Frost"
next
Text2.Caption = time
Timer1.Interval = 1
Label1.Caption = ""
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Time
End Sub

1) I cant get the timer to go into hundreths or miliseconds.
2) I cant get the form to print the time on the timer into Text1 When it loads up
3) I cant get my loop to work, i have no idea why haha.
4) I cant get the form to print the time on the timer into Text2 When the loops finished.

Thanks so much for any help you can give, im just totally bamboozled as to how i'm supposed to do this.

I cant get it to work and i have been trying for 2 hours +

thanks again

Frost

P.S I have tried to enclose a screenshot of my program not quite the same as the one above but gives you the idea.

http://img81.exs.cx/img81/8927/vb6rg.jpg
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Frost is offline Offline
3 posts
since Jan 2005
Jan 22nd, 2005
0

Re: Text Timer

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Form_Load()
  2. Text1.text = time
  3.  
  4. for x = 1 to 10000
  5. Print "Frost"
  6. next
  7.  
  8. Text2.text = time
  9. Timer1.Interval = 1
  10. Label1.Caption = ""
  11. End Sub
  12.  
  13. Private Sub Timer1_Timer()
  14. Label1.Caption = Time
  15. End Sub
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jan 22nd, 2005
0

Re: Text Timer

cheers m8, that really has helped so much. so helpful this forum!!!

Frost
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Frost is offline Offline
3 posts
since Jan 2005
Jan 22nd, 2005
0

Re: Text Timer

Alright, I've Got It:

You Need To Add A Plain Ole Standard Module (It's A Good Practice), inside of the module add this:

Module Code:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
  2. Public Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long
  3.  
  4. Public Type SYSTEMTIME
  5. wYear As Integer
  6. wMonth As Integer
  7. wDayOfWeek As Integer
  8. wDay As Integer
  9. wHour As Integer
  10. wMinute As Integer
  11. wSecond As Integer
  12. wMilliseconds As Integer
  13. End Type

In your form load event, You'll need this code:

Form Load Code
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim GMTime As SYSTEMTIME
  2. Dim TheTime As String
  3. GetSystemTime GMTime
  4.  
  5. Text1.Text = GMTime.wHour & ":" & GMTime.wMinute & ":" & GMTime.wSecond & "." & GMTime.wMilliseconds
  6.  
  7. For x = 1 To 10000
  8. Print "Frost"
  9. Next
  10.  
  11. GetSystemTime GMTime
  12.  
  13. Text2.Text = GMTime.wHour & ":" & GMTime.wMinute & ":" & GMTime.wSecond & "." & GMTime.wMilliseconds
  14. Timer1.Interval = 1
  15. Label1.Caption = ""

And Lastly in your timer event:

Timer Event Code:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim GMTime As SYSTEMTIME
  2. Dim TheTime As String
  3. GetSystemTime GMTime
  4.  
  5. Label1.Caption = GMTime.wHour & ":" & GMTime.wMinute & ":" & GMTime.wSecond & "." & GMTime.wMilliseconds

So Far, This works flawlessly for me. Let me know how it works for you.... if you need an additional help, let me know.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jan 27th, 2005
0

Re: Text Timer

Quote originally posted by Comatose ...
Alright, I've Got It:

You Need To Add A Plain Ole Standard Module (It's A Good Practice), inside of the module add this:

Module Code:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
  2. Public Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long
  3.  
  4. Public Type SYSTEMTIME
  5. wYear As Integer
  6. wMonth As Integer
  7. wDayOfWeek As Integer
  8. wDay As Integer
  9. wHour As Integer
  10. wMinute As Integer
  11. wSecond As Integer
  12. wMilliseconds As Integer
  13. End Type

In your form load event, You'll need this code:

Form Load Code
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim GMTime As SYSTEMTIME
  2. Dim TheTime As String
  3. GetSystemTime GMTime
  4.  
  5. Text1.Text = GMTime.wHour & ":" & GMTime.wMinute & ":" & GMTime.wSecond & "." & GMTime.wMilliseconds
  6.  
  7. For x = 1 To 10000
  8. Print "Frost"
  9. Next
  10.  
  11. GetSystemTime GMTime
  12.  
  13. Text2.Text = GMTime.wHour & ":" & GMTime.wMinute & ":" & GMTime.wSecond & "." & GMTime.wMilliseconds
  14. Timer1.Interval = 1
  15. Label1.Caption = ""

And Lastly in your timer event:

Timer Event Code:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim GMTime As SYSTEMTIME
  2. Dim TheTime As String
  3. GetSystemTime GMTime
  4.  
  5. Label1.Caption = GMTime.wHour & ":" & GMTime.wMinute & ":" & GMTime.wSecond & "." & GMTime.wMilliseconds

So Far, This works flawlessly for me. Let me know how it works for you.... if you need an additional help, let me know.

wow!!! i cant thank you enough that is absolutely perfect!!! well done! Sorry its a little bit late, was away for a couple of days.

(a happy)Frost
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Frost is offline Offline
3 posts
since Jan 2005
Jan 27th, 2005
0

Re: Text Timer

Quote originally posted by Frost ...
wow!!! i cant thank you enough that is absolutely perfect!!! well done! Sorry its a little bit late, was away for a couple of days.

(a happy)Frost
My Pleasure. If you need any other assistance, just let me know.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 1st, 2005
0

Re: Text Timer

Be aware that the time is updated in Windows once every eighteenth of a second. Unless your compiler has a way to access the hardware real time clock outside the Windows I/O period, 1/18 s will be the limit of your resolution.

Windows was designed for business, not science.
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
Real-tiner is offline Offline
207 posts
since Dec 2004
Feb 1st, 2005
0

Re: Text Timer

I didn't Know that. I appreciate that knowledge, since 1/18th isn't as reliable of a system to the millisecond. May I ask where you found this information?
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Dec 9th, 2005
0

Re: Text Timer

Quote originally posted by Comatose ...
I didn't Know that. I appreciate that knowledge, since 1/18th isn't as reliable of a system to the millisecond. May I ask where you found this information?
The hard way - by trying to control real-time processes.

1/18 second = 55 ms = the length of a Windows jiffy (timeslice). The hardware interrupts the Intel-type computer every 55 ms to switch processes in multiprocessing operating systems such as Windows.

All I/O is done at the beginning of each timeslice when Windows does its mousekeeping. Any I/O request by a program has to wait for the next jiffy.
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
Real-tiner is offline Offline
207 posts
since Dec 2004
Mar 6th, 2007
0

Re: Text Timer

This proved to be very helpful - thanks!
Reputation Points: 10
Solved Threads: 3
Light Poster
mjwest10 is offline Offline
27 posts
since Feb 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Please Help..
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: similar of paintpicture





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC