7 Replies - 786 Views - Last Post: 24 March 2013 - 07:13 PM Rate Topic: -----

#1 eos.paks  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-March 13

Reset value of Label

Posted 22 March 2013 - 08:02 PM

Good Day,

I have a Problem with my Counter,
I want to reset the value of Counter if the Clock is 11:59 PM


This is my code of the Counter

frmMain.Label2.Text = Val(frmMain.Label2.Text) + 1

Is there any way to Reset it to 0 everyday?

Regards
Paks
Is This A Good Question/Topic? 0
  • +

Replies To: Reset value of Label

#2 maj3091  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,776
  • Joined: 26-March 09

Re: Reset value of Label

Posted 23 March 2013 - 01:54 AM

Is this VB6 or VB.Net?

It would be useful to see some more of your code or at least a description on what timer interval you're using to update your counter and what you've tried so far to achieve what you want.
Was This Post Helpful? 0
  • +
  • -

#3 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Reset value of Label

Posted 23 March 2013 - 07:49 PM

Have a look at the Time function. You can check it and if you're past midnight, you can set the counter to 0.
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,467
  • Joined: 29-May 08

Re: Reset value of Label

Posted 23 March 2013 - 08:38 PM

moving to vb.net
Was This Post Helpful? 0
  • +
  • -

#5 IronRazer  Icon User is online

  • D.I.C Addict
  • member icon

Reputation: 282
  • Posts: 892
  • Joined: 01-February 13

Re: Reset value of Label

Posted 24 March 2013 - 05:08 AM

Hello maj3091,
You could use an (If Then) statement to see if it equals (12:59 PM) and reset it like
        If Label1.Text = "12:59 PM" Then
            'Reset label
        End If


However if you want just a regular clock then you can use the DateTime.TimeOfDay like this simple clock exampl
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()
        Timer1.Interval = 1000
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'Used Substring to get just the time with no date in it.
        Label1.Text = TimeOfDay.ToString.Substring(TimeOfDay.ToString.IndexOf(" ") + 1)
    End Sub
End Class



Here is a Link to the info on the DateTime at msdn.

This post has been edited by IronRazer: 24 March 2013 - 05:14 AM

Was This Post Helpful? 0
  • +
  • -

#6 eos.paks  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-March 13

Re: Reset value of Label

Posted 24 March 2013 - 06:15 PM

Good Day,

Thank you for your Response

frmMain.Label2.Text = Val(frmMain.Label2.Text) + 1 is my code for the Counter.

but the Problem is, How can i reset it everyday? because the value of it is Continues

it only reset if you close the Application and then open again. the Value become 0 and continue again.

Regards,
Paks
Was This Post Helpful? 0
  • +
  • -

#7 IronRazer  Icon User is online

  • D.I.C Addict
  • member icon

Reputation: 282
  • Posts: 892
  • Joined: 01-February 13

Re: Reset value of Label

Posted 24 March 2013 - 06:50 PM

Hello,
You might want to reset it at "1:00:00 AM" to keep it in sync. However, you can set the text to "12:59:59 PM" if thats what you need. You will have to place it in a timer event that ticks at least 1 time every second to keep it close. Maybe faster if you want it to be real accurate.
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If TimeOfDay.ToString.Substring(TimeOfDay.ToString.IndexOf(" ") + 1) = "1:00:00 AM" Then
            Label1.Text = "0"
        End If
    End Sub


:bigsmile:
Was This Post Helpful? 1
  • +
  • -

#8 eos.paks  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-March 13

Re: Reset value of Label

Posted 24 March 2013 - 07:13 PM

View PostIronRazer, on 24 March 2013 - 06:50 PM, said:

Hello,
You might want to reset it at "1:00:00 AM" to keep it in sync. However, you can set the text to "12:59:59 PM" if thats what you need. You will have to place it in a timer event that ticks at least 1 time every second to keep it close. Maybe faster if you want it to be real accurate.
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If TimeOfDay.ToString.Substring(TimeOfDay.ToString.IndexOf(" ") + 1) = "1:00:00 AM" Then
            Label1.Text = "0"
        End If
    End Sub


:bigsmile:/>



Good Day,

Thank you Problem solved.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1