Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7491535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:04:21+00:00 2026-05-29T16:04:21+00:00

I have a collection in Visual Basic.net (Sorry if people are seeing this code

  • 0

I have a collection in Visual Basic.net (Sorry if people are seeing this code for the nine billionth time…)

Here’s the code so far:

Public Class MainFrm

Private _storage As New List(Of StopwatchStorage)

Public TotalParticipants As Integer ' The total number of participants, will be set via an options form.
Private participantLbl As Label ' A label which will hold the ordered number.
Public participantName As TextBox ' A blank textbox to allow the user to name the participant
Private participantClock As Label ' This is a label which will display the stopwatch
Public ParticipantStop As Button ' A button used to the stop the timer on the participant.
Private participantContinue As Button ' A button used to continue the timer when accidentally stopped.
Private participantTimer As Timer ' A timer to continuously update the labels on pulses.
Public eventName As String = "" ' The Event name itself

' The options
Public numEntrants As Integer = 30 ' The maximum number of participants, set at 30 by default.
Public startingEntrants As Integer = 2 ' The number of timers to start simultaneously., set a 2 by default
Public entryTimer As Integer = 90 ' The timer to seperate and space the entries. Set to 90 by default
Public addAuto As Boolean = False ' A checkbox to determine whether or not to automatically add a participant.

Dim counterTimer As Integer ' A simple holder to count down the entryTimer.

Private participantContinueTimers As TimeSpan
Private participantContinuation As New Stopwatch ' A Stopwatch to hold the continuation timer in the event of an error
Private participantStopwatch As New Stopwatch
Private matchStopwatch As New Stopwatch

Private Sub Participant_Stop(sender As Object, args As EventArgs)
    For Each storage As StopwatchStorage In _storage
        If storage.Button Is sender Then
            storage.Stopwatch.Stop()
            storage.Button.Visible = False
            storage.ContinueBtn.Visible = True

            ' Reset the Continuation timer
            storage.Continuation.Start()
        End If
    Next
End Sub


Private Sub StartButton_Click(sender As System.Object, e As System.EventArgs) Handles StartButton.Click
    For indexCounter As Integer = 1 To startingEntrants Step 1
        DrawControls(indexCounter)
    Next
End Sub


Private Sub Participant_Resume(sender As Object, args As EventArgs)
    For Each storage As StopwatchStorage In _storage
        If storage.ContinueBtn Is sender Then
            storage.ContinueBtn.Visible = False
            storage.Button.Visible = True
            storage.Stopwatch.Start()
            storage.Continuation.Stop()

            ' Add the value from storage.Continuation.Elapsed to a continuing tally
            storage.ParticipantContinueTimers += storage.Continuation.Elapsed
            storage.Continuation.Reset()
        End If
    Next
End Sub

Private Sub DrawControls(records As Integer)
    participantLbl = New Label
    participantLbl.Location = New Point(5 + (((records - 1) \ 15) * 321), 5 + (((records - 1) Mod 15) * 26))
    participantLbl.Size = New Size(22, 20)
    participantLbl.TextAlign = ContentAlignment.MiddleCenter
    participantLbl.Text = records
    CenterPanel.Controls.Add(participantLbl)

    participantName = New TextBox
    participantName.Location = New Point(31 + (((records - 1) \ 15) * 321), 5 + (((records - 1) Mod 15) * 26))
    participantName.Size = New Size(105, 20)
    CenterPanel.Controls.Add(participantName)

    participantClock = New Label
    participantClock.Size = New Size(100, 20)
    participantClock.Name = "participantClock" & TotalParticipants
    participantClock.Location = New Point(139 + (((records - 1) \ 15) * 321), 5 + (((records - 1) Mod 15) * 26))
    participantClock.BorderStyle = BorderStyle.Fixed3D
    participantClock.TextAlign = ContentAlignment.MiddleRight
    CenterPanel.Controls.Add(participantClock)

    ParticipantStop = New Button
    ParticipantStop.Size = New Size(63, 20)
    ParticipantStop.Location = New Point(245 + (((records - 1) \ 15) * 321), 5 + (((records - 1) Mod 15) * 26))
    ParticipantStop.BackColor = Color.Red
    ParticipantStop.ForeColor = Color.White
    ParticipantStop.Font = New Font(ParticipantStop.Font, FontStyle.Bold)
    ParticipantStop.Text = "Stop"
    CenterPanel.Controls.Add(ParticipantStop)
    AddHandler ParticipantStop.Click, AddressOf Participant_Stop


    participantContinue = New Button
    participantContinue.Size = New Size(63, 20)
    participantContinue.Location = New Point(245 + (((records - 1) \ 15) * 321), 5 + (((records - 1) Mod 15) * 26))
    participantContinue.BackColor = Color.Green
    participantContinue.ForeColor = Color.White
    participantContinue.Font = New Font(participantContinue.Font, FontStyle.Bold)
    participantContinue.Text = "Resume"
    participantContinue.Visible = False
    CenterPanel.Controls.Add(participantContinue)
    AddHandler participantContinue.Click, AddressOf Participant_Resume

    participantTimer = New Timer
    participantTimer.Start()
    participantTimer.Enabled = True
    participantTimer.Interval = 1
    participantStopwatch = New Stopwatch
    participantStopwatch.Start()


    Dim storage As New StopwatchStorage()
    storage.Label = participantClock
    storage.Timer = participantTimer
    storage.Continuation = participantContinuation
    storage.Button = ParticipantStop
    storage.ParticipantContinueTimers = participantContinueTimers
    storage.ContinueBtn = participantContinue
    storage.ParticipantName = participantName
    storage.ParticipantOrder = participantLbl
    storage.Stopwatch = participantStopwatch
    _storage.Add(storage)
    AddHandler participantTimer.Tick, AddressOf Timer_Tick

End Sub


End Class
Public Class StopwatchStorage
Public Property Stopwatch As Stopwatch
Public Property Continuation As Stopwatch
Public Property ParticipantContinueTimers As TimeSpan
Public Property ParticipantName As TextBox
Public Property Label As Label
Public Property ParticipantOrder As Label
Public Property Timer As Timer
Public Property Button As Button
Public Property ContinueBtn As Button
End Class

What’s supposed to happen is that the Stop Button when clicked is supposed to start another timer/stopwatch. When you click the Resume Button, the value of the stopwatch is supposed to be added back onto the running timer. (It gets added to `participantContinueTimers which is then add back onto the running timer.) Now the code is doing what it’s supposed to do, BUT, instead of adding the particular of that one stopped clock, it adds ALL of the values of the stopped click then resets.

Can someone explain how can I get this to work so that only the ONE stopped result is added on?

EDIT: Adding in the method in which the Storages are made. Any more code and I’ll have to host it on SourceForge or Codeplex and work from there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T16:04:22+00:00Added an answer on May 29, 2026 at 4:04 pm

    You should not use member variables for your dynamical controls. On this way you are overriding all controls and only the last one wins. Instead you should create them in the method separately. You are also using a parameter records, but i don’t see the code where you loop it to create more than one StopwatchStorage.

    Private Sub DrawControls(records As Integer)
        Dim participantLbl = New Label
        participantLbl.Location = New Point(5 + (((records - 1) \ 15) * 321), 5 + (((records - 1) Mod 15) * 26))
        participantLbl.Size = New Size(22, 20)
        participantLbl.TextAlign = ContentAlignment.MiddleCenter
        participantLbl.Text = records
        CenterPanel.Controls.Add(participantLbl)
    
        Dim participantName = New TextBox
        participantName.Location = New Point(31 + (((records - 1) \ 15) * 321), 5 + (((records - 1) Mod 15) * 26))
        participantName.Size = New Size(105, 20)
        CenterPanel.Controls.Add(participantName)
    
        Dim participantClock = New Label
        participantClock.Size = New Size(100, 20)
        participantClock.Name = "participantClock" & TotalParticipants
        participantClock.Location = New Point(139 + (((records - 1) \ 15) * 321), 5 + (((records - 1) Mod 15) * 26))
        participantClock.BorderStyle = BorderStyle.Fixed3D
        participantClock.TextAlign = ContentAlignment.MiddleRight
        CenterPanel.Controls.Add(participantClock)
    
        Dim ParticipantStop = New Button
        ParticipantStop.Size = New Size(63, 20)
        ParticipantStop.Location = New Point(245 + (((records - 1) \ 15) * 321), 5 + (((records - 1) Mod 15) * 26))
        ParticipantStop.BackColor = Color.Red
        ParticipantStop.ForeColor = Color.White
        ParticipantStop.Font = New Font(ParticipantStop.Font, FontStyle.Bold)
        ParticipantStop.Text = "Stop"
        CenterPanel.Controls.Add(ParticipantStop)
        AddHandler ParticipantStop.Click, AddressOf Participant_Stop
    
    
        Dim participantContinue = New Button
        participantContinue.Size = New Size(63, 20)
        participantContinue.Location = New Point(245 + (((records - 1) \ 15) * 321), 5 + (((records - 1) Mod 15) * 26))
        participantContinue.BackColor = Color.Green
        participantContinue.ForeColor = Color.White
        participantContinue.Font = New Font(participantContinue.Font, FontStyle.Bold)
        participantContinue.Text = "Resume"
        participantContinue.Visible = False
        CenterPanel.Controls.Add(participantContinue)
        AddHandler participantContinue.Click, AddressOf Participant_Resume
    
        Dim participantTimer = New Timer
        participantTimer.Start()
        participantTimer.Enabled = True
        participantTimer.Interval = 1
        participantStopwatch = New Stopwatch
        participantStopwatch.Start()
    
    
        Dim storage As New StopwatchStorage()
        storage.Label = participantClock
        storage.Timer = participantTimer
        storage.Continuation = participantContinuation
        storage.Button = ParticipantStop
        storage.ParticipantContinueTimers = participantContinueTimers
        storage.ContinueBtn = participantContinue
        storage.ParticipantName = participantName
        storage.ParticipantOrder = participantLbl
        storage.Stopwatch = participantStopwatch
        _storage.Add(storage)
        AddHandler participantTimer.Tick, AddressOf Timer_Tick
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just testing out some basic networking code written in Visual C++. I have
I there I have this scenario: a) Notebook :Windows Server 2008 R1, Visual basic
I have Collection List<Car> . How to compare each item from this collection with
I have an old visual basic 6 application when some users reported me errors
This code was once working on sql server 2005. Now isolated in a visual
Trying to do basic SSL-authenticated Web Service using Visual Studio 2008 .NET 3.5 Service
Using the C# code below, how would you write it in Visual Basic? What
I am using Microsoft Visual Basic 2010 Express. I have a WPF-based project. I
Suppose you have a TFS collection with a Samples project that contain your Visual
We have a Visual Basic application inside of Microsoft Access and we need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.