Timer help. - VB.net menu

Shout-Out

User Tag List

Results 1 to 10 of 10
  1. #1
    Fireking300's Avatar Active Member
    Reputation
    27
    Join Date
    Jun 2007
    Posts
    92
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Timer help. - VB.net

    Basically I am making a application that says what time it is and what class period it is. And how many minutes till the next or other class periods start. I want it to change the labels everytime timer1_Tick happens to the appropriate text. Whenever it is a weekend I want label8.text to say Today is a weekend. And if it is a holiday for my school I want it to say It is a holiday. And if it is the last day of school I want it to say that. The only hard part I am having is making the labels that say how much longer till that period.

    Code:
    Public Class Form1
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Me.Text = TimeOfDay() + " - " + DateString
            \\\ CODING
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Timer1.Start()
        End Sub
    End Class
    Code:
    Weekends - 
    03-01-2009
    03-07-2009
    03-08-2009
    03-14-2009
    03-15-2009
    03-21-2009
    03-22-2009
    03-28-2009
    03-29-2009
    04-04-2009
    04-05-2009
    04-11-2009
    04-12-2009
    04-18-2009
    04-19-2009
    04-25-2009
    04-26-2009
    05-02-2009
    05-03-2009
    05-09-2009
    05-10-2009
    05-16-2009
    05-17-2009
    05-23-2009
    05-24-2009
    05-30-2009
    05-31-2009
    Holidays - 
    03-16-2009
    03-17-2009
    03-18-2009
    03-19-2009
    03-20-2009
    04-10-2009
    05-25-2009
    Last Day of School -
    06-04-2009

    Timer help. - VB.net
  2. #2
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Set some variables for periods etc, and use If.

    Code:
    HolidaysArray() = {You know how to set an array, right?}
    For x = 1 to numberofholidays
        If DateString = HolidaysArray(x) Then
            MsgBox("Holiday today")
        End If
    Next x
    For the holidays, and for last day:

    Code:
    If DateString = "06-04-2009" Then MsgBox("Last Day of School")
    As to the "how long" stuff, just set a time for them and compare with the current time (hour, minute and second part) then update.

    Edit: Having turned on my brain and remembered how to use the DateTime functions, I can be more helpful.

    Add this to the Timer1_Tick sub:
    Code:
    Dim Hours as Integer = DateTime.Hour
    Dim Minutes as Integer = DateTime.Minute
    Dim Seconds as Integer = DateTime.Second
    
    Hours = NextPeriodHour - Hours
    Minutes = NextPeriodMinute - Minutes
    Seconds = NextPeriodSecond - Seconds
    I'm sure you can set the hour, minute and second for the next period. The variables that get updated on each tick will give you the time till the next event. Working from there shouldn't be too hard. Hope that helps.
    Last edited by ReidE96; 02-28-2009 at 04:58 PM.

  3. #3
    Fireking300's Avatar Active Member
    Reputation
    27
    Join Date
    Jun 2007
    Posts
    92
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could I do it like this?
    I make 3 textboxes one of each category. Weekend, Holiday, and Last day of school.
    Each with the dates seperated by a new line.
    And then make three
    Code:
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If DateString = ????? Then
                Label8.Text = "Today is a weekend."
            End If
            If DateString = ????? Then
                Label8.Text = "Today is a holiday."
            End If
            If DateString = ????? Then
                Label8.Text = "Today is the last day of school."
            End If
        End Sub

  4. #4
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure thing. I just used MsgBox as an example. Though I would recommend putting the holidays and weekends into arrays in order to check them all. Saves repeating your code several times, cause you can just use a For loop.

  5. #5
    Fireking300's Avatar Active Member
    Reputation
    27
    Join Date
    Jun 2007
    Posts
    92
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i don't know how to use a array but ill try to learn.

  6. #6
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seriously? Arrays are VERY useful. I'm surprised you don't know about them.

  7. #7
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Erm...

    Code:
    Dim thisYear As Integer = DateTime.Now.Year
        Dim firstPeriod As New DateTime(thisYear, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0)
        ' 8AM
        Dim secondPeriod As New DateTime(thisYear, DateTime.Now.Month, DateTime.Now.Day, 9, 0, 0)
        ' 9AM
        ' Etc.
        Dim holidays As New List(Of DateTime)()
        holidays.Add(New DateTime(thisYear, 3, 16, 0, 0, 0))
        holidays.Add(New DateTime(thisYear, 3, 17, 0, 0, 0))
        holidays.Add(New DateTime(thisYear, 3, 18, 0, 0, 0))
        holidays.Add(New DateTime(thisYear, 3, 19, 0, 0, 0))
        holidays.Add(New DateTime(thisYear, 3, 20, 0, 0, 0))
        holidays.Add(New DateTime(thisYear, 4, 10, 0, 0, 0))
        holidays.Add(New DateTime(thisYear, 5, 25, 0, 0, 0))
        
        Dim lastDayOfSchool As New DateTime(thisYear, 6, 4, 0, 0, 0)
        If DateTime.Now.DayOfWeek = DayOfWeek.Saturday OrElse DateTime.Now.DayOfWeek = DayOfWeek.Sunday OrElse DateTime.Now.DayOfYear = lastDayOfSchool.DayOfYear Then
            ' Weekend or last day of school.
        End If
        For Each time As DateTime In holidays
            If DateTime.Now.DayOfYear = time.DayOfYear Then
                ' Holiday
            End If
        Next
        If DateTime.Now < firstPeriod Then
            Console.WriteLine(DateTime.Now.Subtract(firstPeriod) & " before 1st period is over.")
        ElseIf DateTime.Now < secondPeriod Then
            Console.WriteLine(DateTime.Now.Subtract(secondPeriod) & " before 2nd period is over.")
        End If
        ' Etc.

  8. #8
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Apoc View Post
    Erm...

    Code:
    Dim thisYear As Integer = DateTime.Now.Year
        Dim firstPeriod As New DateTime(thisYear, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0)
        ' 8AM
        Dim secondPeriod As New DateTime(thisYear, DateTime.Now.Month, DateTime.Now.Day, 9, 0, 0)
        ' 9AM
        ' Etc.
        Dim holidays As New List(Of DateTime)()
        holidays.Add(New DateTime(thisYear, 3, 16, 0, 0, 0))
        holidays.Add(New DateTime(thisYear, 3, 17, 0, 0, 0))
        holidays.Add(New DateTime(thisYear, 3, 18, 0, 0, 0))
        holidays.Add(New DateTime(thisYear, 3, 19, 0, 0, 0))
        holidays.Add(New DateTime(thisYear, 3, 20, 0, 0, 0))
        holidays.Add(New DateTime(thisYear, 4, 10, 0, 0, 0))
        holidays.Add(New DateTime(thisYear, 5, 25, 0, 0, 0))
        
        Dim lastDayOfSchool As New DateTime(thisYear, 6, 4, 0, 0, 0)
        If DateTime.Now.DayOfWeek = DayOfWeek.Saturday OrElse DateTime.Now.DayOfWeek = DayOfWeek.Sunday OrElse DateTime.Now.DayOfYear = lastDayOfSchool.DayOfYear Then
            ' Weekend or last day of school.
        End If
        For Each time As DateTime In holidays
            If DateTime.Now.DayOfYear = time.DayOfYear Then
                ' Holiday
            End If
        Next
        If DateTime.Now < firstPeriod Then
            Console.WriteLine(DateTime.Now.Subtract(firstPeriod) & " before 1st period is over.")
        ElseIf DateTime.Now < secondPeriod Then
            Console.WriteLine(DateTime.Now.Subtract(secondPeriod) & " before 2nd period is over.")
        End If
        ' Etc.

    Fail. True story.

  9. #9
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here comes Apoc the epic to save the day with better knowledge than the rest of us XD

  10. #10
    Araredon's Avatar Contributor
    Reputation
    89
    Join Date
    Feb 2009
    Posts
    141
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well if you want it to simply say the date/time in a label do this:

    label1.text = timeofday
    or
    label1.text = datestring
    Id put that in the Form_load event, it will automatically update every second/day.
    Not sure if that helps but that's how i do date/time

    EDIT: Just realized you already had that in your code :P
    Last edited by Araredon; 03-01-2009 at 06:23 PM.
    Dont read this. It has nothing to do with you. Are you still reading? Why are you still reading? I told you not to read. It doesnt have anything to do with you. Are you happy now? You just wasted atleast 5 seconds of your life reading nothing.

Similar Threads

  1. Need help! Battle.net name change!
    By Dassell in forum World of Warcraft General
    Replies: 4
    Last Post: 04-11-2013, 02:19 PM
  2. Thread32First help vb.net
    By abuckau907 in forum WoW Memory Editing
    Replies: 0
    Last Post: 06-11-2009, 07:47 PM
  3. [HELP] F#.NET Addin for VS 2008(Shell)
    By Clain in forum Programming
    Replies: 1
    Last Post: 01-02-2009, 09:59 AM
  4. Net tools help SMTP
    By pixie12 in forum Community Chat
    Replies: 1
    Last Post: 05-08-2008, 06:53 PM
  5. [VB.NET] I give up. Need help! Socket related
    By ReidE96 in forum Programming
    Replies: 3
    Last Post: 04-25-2008, 01:20 PM
All times are GMT -5. The time now is 07:16 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search