Results 1 to 2 of 2

Thread: Button That Resets Label

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    7

    Button That Resets Label

    Hello Guys! I am currently working on a Work Hour Calculator to calculate all your hours after you work! Well I am almost completely finished although I have one problem.

    I have buttons that say different hour amounts. When you click it, the label updates and places that number on the label. If you click another amount, it adds on the amount you first clicked on and updates the label. Well, I'm wanting to make it so you click on "New" and the label resets and then you can start counting hours from scratch again.

    One problem though, lets say I put in 30 hours, well when I click "New", the label goes back down to 0. But when I click on 1 Hour lets say, it goes to 31 because the code didn't reset the background information so the program still thinks it's adding. So I need help with actually resetting it to 0 and it starts new again.

    Anyone?

    Here is my full code for my whole form that I thought of.

    Code:
    Public Class Form1
        Public clicks As Decimal
        Dim dtmTest As Date
        Dim counter As Integer = 1
    
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
            clicks += 1
            LabelX2.Text = clicks
    
        End Sub
    
        Private Sub ButtonX12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            MsgBox("Adding Half Hours")
        End Sub
    
        Private Sub ButtonX2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX2.Click
            clicks += 2
            LabelX2.Text = clicks
        End Sub
    
        Private Sub ButtonX3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX3.Click
            clicks += 3
            LabelX2.Text = clicks
        End Sub
    
        Private Sub ButtonX4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX4.Click
            clicks += 4
            LabelX2.Text = clicks
        End Sub
    
        Private Sub ButtonX5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX5.Click
            clicks += 5
            LabelX2.Text = clicks
        End Sub
    
        Private Sub ButtonX6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX6.Click
            clicks += 6
            LabelX2.Text = clicks
        End Sub
    
        Private Sub ButtonX8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX8.Click
            clicks += 7
            LabelX2.Text = clicks
        End Sub
    
        Private Sub ButtonX7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX7.Click
            clicks += 8
            LabelX2.Text = clicks
        End Sub
    
        Private Sub ButtonX9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX9.Click
            clicks += 9
            LabelX2.Text = clicks
        End Sub
    
        Private Sub ButtonX10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX10.Click
            clicks += 10
            LabelX2.Text = clicks
        End Sub
    
        Private Sub ButtonX14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX14.Click
            clicks += 11
            LabelX2.Text = clicks
        End Sub
    
        Private Sub ButtonX15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX15.Click
            clicks += 12
            LabelX2.Text = clicks
        End Sub
    
        Private Sub ButtonX11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX11.Click
            clicks += 0.5
            LabelX2.Text = clicks
        End Sub
    
        Private Sub ButtonX12_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim lblTask As New Label
            lblTask.Name = "Label" & counter
            lblTask.Size = New Size(87, 23)
            lblTask.Location = New Point(12, counter * 22)
            lblTask.Text = getCurrentDateTimeString() & " " & " " & " " & " " & " " & Me.LabelX2.Text
            History.Controls.Add(lblTask)
            counter += 1
    
    
        End Sub
    
        Private Sub LabelX4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
        Public Shared Function getCurrentDateTimeString() As String ' Returns current date and time in this format: "yyyyMMddHHmmssff"         Dim rightNow As DateTime = DateTime.Now         Dim strCurrentDateTimeString As String         strCurrentDateTimeString = rightNow.ToString("yyyyMMddHHmmssff")         Return (strCurrentDateTimeString)     End FunctionPublic Shared Function getCurrentDateTimeString() As String ' Returns current date and time in this format: "yyyyMMddHHmmssff"
            Dim rightNow As DateTime = DateTime.Now
            Dim strCurrentDateTimeString As String
            strCurrentDateTimeString = rightNow.ToString("yyyy.MM.dd")
            Return (strCurrentDateTimeString)
        End Function
    
        Private Sub HistoryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HistoryToolStripMenuItem.Click
    
            If LabelX2.Text = LabelX1.Text Then
                LabelX2.Text = String.Empty
            End If
    
    
    
        End Sub
    
        Private Sub LabelX2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LabelX2.Click
    
        End Sub
    
        Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
            Dim FileToSaveAs As String = SaveFileDialog1.FileName
    
            Dim objwriter As New System.IO.StreamWriter(FileToSaveAs)
            objwriter.Write(getCurrentDateTimeString() & "       " & LabelX2.Text)
            objwriter.Close()
        End Sub
    
        Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
    
        Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
    
        Private Sub ContactUsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContactUsToolStripMenuItem.Click
            SaveFileDialog1.ShowDialog()
        End Sub
    
    End Class
    and this is the line that I need to use to make the label clear.

    Private Sub HistoryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HistoryToolStripMenuItem.Click

    If LabelX2.Text = LabelX1.Text Then
    LabelX2.Text = String.Empty
    End If



    End Sub

    Usually I only put labelx2.text = string.empty although it does only change the label to 0 but the background information is still at the amount you left off before and isn't fully reset to 0.

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Button That Resets Label

    You are addingthe times into the variable "clicks", if you want to restart you need to clear that variable too!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width