vb.net program to register time on multiple runners - vb.net

I building a program to track the time of up to 60 runners. My idea is to use a DataGridView with columns for:
ID (DataGridViewTextBoxColumn)
Name (DataGridViewTextBoxColumn)
Start time (DataGridViewButtonColumn)
Stop time (DataGridViewButtonColumn)
Reset time (DataGridViewButtonColumn)
Finish time (DataGridViewTextBoxColumn)
Adding columns 1-5 including functions is no problem, but I cannot wrap my head around how to display a stopwatch in column 6.
My idea was to add a timer and stopwatch function every time a new row I added, but do I need a timer for each row? If so how do I set the ID of that timer, so I can call the Tick event and display the time in column 6?
Also I assume that I need a stopwatch for each row? So how do I set the name of ID of each Stopwatch - can seem to find any property for that?
See below screen shot of what I am trying to accomplish.
Thanks in advance.
Screen shot

Related

Seeking suggestion to count time inside the loop

I am trying to measure/count the time inside the while loop, I tried a couple of methods but couldn't find the solution yet.
Here is my current VI.
 
In short, I am trying to measure the time as long as the "Boolean is on/true" and once it's off/false the time must be displayed.
If something is not clear then please let me know.
I may be repeating Fourier's answer, but typing it in two different forms may be helpful to you since I note you haven't accepted that answer yet.
Remove the outer While Loop. It is superfluous.
Then do this:
In the "turn on" frame, you gather the current Tick Count and stash it in a shift register. In the "turn off" frame, you gather the Tick Count again and subtract. In all the other frames, make sure you wire the two tunnels together so you don't lose your Tick Count. Side note: you probably want Boolean to be an indicator, not a control, so your user cannot click on it and toggle it directly.
You can reach your goal with simpler code. You should use one while loop only with the Event Structure:
When List of Conditions changes, intercept the event (as you are already doing) and register the time when this event happen (with the VI Tick count for example).
in two shift registers,"save" the time you registers in the previous point and the status of your count (a boolean should be enough: counting/not counting).
Then, in the Timeout event you calculate in real time the time passed with the following operation current time (Vi Tick count) - event time (save in the shift register).
You should count time only if your boolean Counting/not counting is True.
When you detect another event List of Conditions Value Change, you should check if you should stop count time or not.
Finally, in the Timeout event or in the List of Conditions Value change event, evaluate the stop condition for your while loop.

Count timer for a Quizz on VBA

I'm currently trying to install timer in VBA - I'm working on a quizz.
There are several questions to answer. What I would I like to know is the time that someone spends answering each question. So the timer should start every time someone clicks on question, then stop when someone clicks on question 2 and start again instantly.
OnClick events. Just use a DateDiff to calculate the time spent. Of course, they'd have to click a button to begin the exam, or open the form that contains the exam, so there's an initial reference point. But it should only take a few milliseconds to write that timestamp to a table and then calculate the difference each time the button is clicked.
You can use the Timer function. It will give you a precision up to 1/1000 of a second:
Dim myTime as variant
myTime = Timer
...
Debug.Print "Process duration", Timer - myTime

pictures keep changing on the form, there should be at least 5 pictures on every different groupbox using loop

I want a way of loading 5 pictures on every refresh. i have over 300 pictures in the database and i want them to load every 5 picture on form load. and then they sray there for 10sec and then the next 5 loads n keeps loading till al the pictures are loaded then it restarts again from the start.
it should be using a loop. because i have a dynamic way of loading my pictures and textboxes. so how could i jst load 5 pictured and then the next 5 after the first 5 have disappeared. all should happen on one form. maybe even use ashock.. or any other way.
or any other way.
you can do like this, First get all those 300 pictures in the load event and store that in a datatable (using datatable will shrinks the possibility to connect to back end multiple times).Then use a timer in your form and set its interval for 5000 ms(i.e 5 seconds). use a global variable to to track how many pictures are shown, increment it by 5 for every tick event's call(Tick event will get fired when interval assigned by you gets elapsed. - ex: for every 5 seconds). now inside the tick event, get five pictures from the datatable(use that global variable to get the next 5 images). Display those five images by replacing the old ones.and once that global variable reaches 300 again reset it to 0. This cycle will ends only if you stop the timer.
Hope this will give you an idea to accompolish your task.

Timing a simulation in a control loop

I have a labview vi which is in a control loop with PID . I want to insert a timer for the simulation. It should display the time of the simulation and also use that time to make changes in the control loop.
It is just a simple timer but I am not sure which one and how to use them. please help me
The simplest option, if it does what you need, is probably the 'Elapsed Time' Express VI.
Alternatively you can use the Get Date/Time in Seconds function. Read this function at the start of your simulation and pass the value in to your control loop (or read it on the first loop iteration and store the value in a shift register). Inside the loop, read the same function and subtract the value from the start value; that'll give you the elapsed time in seconds. If you want a display of this value just wire it to a numeric indicator. You can set the display format of the indicator to 'relative time' if you want to show hours, minutes and seconds.
The most natural option would be to use a Timed-loop, this allows you to detect whether your code can run in the supplied time and select a hardware time clock.

VB time input, a better way to do it?

Working on a handy program for my boss at work as a summer project in between semesters both to make life easier for her, and to practice and improve my skills. Intent is to allow her to quickly and easily calculate the hours and minutes the person worked. The form itself has a series of text boxes for the Clock in and Clock out time for each day that week. Currently it attempts to convert the txtbox text into a Date variable, then .Subtract()'s the start from the end and stores it in a rolling total variable which is displayed at the bottom of the form. I can't help but think there is a better way of going about doing this, and I'm absolutely certain that having the below block of code 21 times (7 days, 3 shifts) is inefficient.
Dim StartTime As Date
Dim EndTime As Date
Dim Worked As System.TimeSpan
Dim WorkedTotal As System.TimeSpan
If chkFirst.Checked = True Then
StartTime = CDate(txtMonStart.Text)
EndTime = CDate(txtMonEnd.Text)
EndTime = EndTime.AddHours(12)
Worked = EndTime.Subtract(StartTime)
lblMonWork.Text = Worked.ToString()
WorkedTotal += Worked
Currently it works, mostly. The user has to enter the ":" in the time input, and if the total exceeds 24 hours, it displays a day column (40 hour 12 min work week displays as 1.16:12). I'd like to eliminate both of these unplanned features and allow for my input validation to take place when the focus changes to another box. A changing bgcolor would indicate an invalid input.
Any bright ideas?
Instead of using TextBox for the time input, use DateTimePicker, just change the Format property to Time.
Handle the Validating event of the DateTimePicker and if it's invalid just set e.Cancel = False, that way they can't save changes unless it's valid. Or if you want them to be able to leave the DateTimePicker and just change the colour, just handle the ValueChanged event instead.
Regarding your code sample, I haven't really looked at the logic of it, but instead of having the same code 21 times, just move the code into a separate function and then call that function with the start and end times as parameters and it can return the workedtime as it's return value.
I'm not sure what your UI looks like but if you're repeating the start time and end time input control multiple times as well it might be worth looking at creating your own usercontrol that can contain one each of the start and end time controls, and then you could have the validation be inside that user control so you don't have to have lots of event handlers etc.