Label with time?

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
14 posts Page 1 of 2
Contributors
User avatar
troop
Dedicated Member
Dedicated Member
Posts: 75
Joined: Sat Sep 28, 2013 11:57 am

Label with time?
troop
hi, im making a program but there is a problem

for example if i make a alarm for 150 seconds it will show on label "150" and timer will keep -1 from it until "if label.text = 0 then msgbox("alarm!") but
the problem is how can i make the label be real time instead of seconds



like if i choose a 5 min alarm it dont show "300" seconds it show "00:05:00" if 1 hour then "00:60:00"
and how will even i decrease the timer if i use this please help :D

u dont need to teach but if u have a video or website tell me :P
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: Label with time?
Shim
Hi,

Have a look at this - http://www.tutorialspoint.com/vb.net/vb ... e_time.htm

It has properties and methods of the DateTime structure
Find my programs on Softpedia
User avatar
troop
Dedicated Member
Dedicated Member
Posts: 75
Joined: Sat Sep 28, 2013 11:57 am

Re: Label with time?
troop
thanks but this just prints out date and time it doesnt teach what i need :/
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: Label with time?
Shim
So do you want to get the real time on a label? that's it?
Find my programs on Softpedia
User avatar
troop
Dedicated Member
Dedicated Member
Posts: 75
Joined: Sat Sep 28, 2013 11:57 am

Re: Label with time?
troop
no no no!
i thin i didnt explain good, here is the reason,

FOR example I made a alarm clock. and I set alarm NOT in exact time like "9:59 AM" i want it to be…
ok look, i have buttons each is like "in 1 hour" "in 3 mins" so when they click it, the alarm is set after 3 mins so it should LOOK like "00:03:00" and then timer will remove 1 sec from it with interval of 1000, until it reaches 00:00:00 the alarm will work.

EVERYTHING is fine with me but I want to know how can i decrease time in this method

if label is 00:13:00 and I do label1.text -= 1 it will not work! thats what i need
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Re: Label with time?
Dummy1912
maybe this helps
Code: Select all
   Private TDT As DateTime
   Private CountFrom As TimeSpan = TimeSpan.FromMinutes(3)

    Private Sub form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        timer1.Interval = 500
        TDT = DateTime.Now.Add(CountFrom)
        timer1.Start()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick
        Dim ts As TimeSpan = TDT.Subtract(DateTime.Now)
        If ts.TotalMilliseconds > 0 Then
            label1.Text = ts.ToString("HH:mm\:ss")
        Else
            label1.Text = "00:00:00"
            tmrCountdown.Stop()
            MessageBox.Show("Done")
        End If
    End Sub
hope this is what you are after :)
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

Re: Label with time?
XTechVB
To convert seconds to minutes you can also do this
Code: Select all
300 / 60
You can find me on Facebook or on Skype mihai_92b
User avatar
noypikami
VIP - Donator
VIP - Donator
Posts: 151
Joined: Sat Dec 22, 2012 1:49 am

Re: Label with time?
noypikami
try this out, THIS CAN HELP YOU BUILD YOUR PROJECT
use "datediff" to calculate the time difference"
here's the full code:
Code: Select all
Class Form1

    Dim startTIME As Date
    Dim endTIME As Date
    Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      
      
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label6.Text = "Starting Time :  " & startTIME
        Label1.Text = "Current time  :  " & DateAndTime.TimeOfDay
        Label2.Text = "Alarm time    :  " & endTIME
        Dim timeDif As Long = DateDiff(DateInterval.Second, startTIME, endTIME)
        Label3.Text = "Total Time difference : " & timeDif & "  Seconds"
        Dim timecounter As Long = DateDiff(DateInterval.Second, DateAndTime.TimeOfDay, endTIME)
        Label4.Text = "Remaining time : " & timecounter & " Seconds"
        If timecounter <= 0 Then
            timecounter = 0
            Timer1.Stop()
           
            MsgBox("DONE")
        End If


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        startTIME = DateAndTime.TimeString
        endTIME = startTIME.AddSeconds(NumericUpDown1.Text)  'add seconds
        Timer1.Start()

       
    End Sub
End Class

here's the exe file :
time settings.rar
here's the full project :
time diff.rar
You do not have the required permissions to view the files attached to this post.
Last edited by noypikami on Wed Jan 15, 2014 3:03 pm, edited 2 times in total.
User avatar
troop
Dedicated Member
Dedicated Member
Posts: 75
Joined: Sat Sep 28, 2013 11:57 am

Re: Label with time?
troop
OMG thanks brothers! cryer; loove;

I think the last 2 ones are what i need i will try them now and say if it work :) :D thanks omg; wahooo; loove;
User avatar
troop
Dedicated Member
Dedicated Member
Posts: 75
Joined: Sat Sep 28, 2013 11:57 am

Re: Label with time?
troop
hey dummy
in timer tick event
ts.ToString("HH:mm\:ss") shows to be an error :/


"Overload resolution failed because no accessible 'ToString' accepts this number of arguments."

:3
14 posts Page 1 of 2
Return to “Coding Help & Support”