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.
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 37 times

jvierra
Posts: 14836
Last visit: Sat Jun 19, 2021 7:13 am
Answers: 10
Has voted: 3 times
Been upvoted: 10 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: 14836
Last visit: Sat Jun 19, 2021 7:13 am
Answers: 10
Has voted: 3 times
Been upvoted: 10 times

Re: Need some help with script for stopwatch

Post by jvierra »

Attached.
Attachments
Demo-Timer.psf
(43.65 KiB) Downloaded 40 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: 14836
Last visit: Sat Jun 19, 2021 7:13 am
Answers: 10
Has voted: 3 times
Been upvoted: 10 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 45 times

Locked