Need some help with script for stopwatch

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 2 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
SanSiets
Posts: 11
Last visit: Tue May 04, 2021 3:50 pm

Need some help with script for stopwatch

Post by SanSiets »

In the attached files I have a script for Powershell studio.
The code is for a stopwacht function.

The problem is that the first time I start the stopwatch via the startbutton it works good but when I press the stop button and then again on the start button it added up with 2 seconds instead of 1.

Can someone please help me/improve my script?

Thanks in advance.
Attachments
Stopwatch.psf
(119.95 KiB) Downloaded 97 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Need some help with script for stopwatch

Post by jvierra »

Why are you creating all of those variables? The timer always holds the value. All you have to do is reset it when you start and then get the value after it stops.

I recommend reading the timer documentation to understand how timers work.
User avatar
SanSiets
Posts: 11
Last visit: Tue May 04, 2021 3:50 pm

Re: Need some help with script for stopwatch

Post by SanSiets »

I'm not that expierenced so that is why I'm asking for help.
Can you please give me an example script or change my script?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Need some help with script for stopwatch

Post by jvierra »

Attached.
Attachments
Demo-Timer.psf
(43.65 KiB) Downloaded 85 times
User avatar
SanSiets
Posts: 11
Last visit: Tue May 04, 2021 3:50 pm

Re: Need some help with script for stopwatch

Post by SanSiets »

Many thanks!!!
You've made my day.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Need some help with script for stopwatch

Post by jvierra »

Here is a cleaner and simpler way.
Attachments
Demo-Timer.psf
(48.67 KiB) Downloaded 107 times
This topic is 2 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked