Results 1 to 13 of 13

Thread: Problem with DateTime.Now.ToString

  1. #1
    Junior Member
    Join Date
    May 11
    Posts
    26

    Problem with DateTime.Now.ToString

    Hi,
    I'm trying to do this :
    Code:
        
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If DateTime.Now.ToString("dddd") = "Sun" Then
                Label1.Text = "Sun"
            ElseIf DateTime.Now.ToString("dddd") = "Mon" Then
                Label1.Text = "Mon"
            ElseIf DateTime.Now.ToString("dddd") = "Tue" Then
                Label1.Text = "Tue"
            ElseIf DateTime.Now.ToString("dddd") = "Wed" Then
                Label1.Text = "Wed"
            ElseIf DateTime.Now.ToString("dddd") = "Thu" Then
                Label1.Text = "Thu"
            ElseIf DateTime.Now.ToString("dddd") = "Fri" Then
                Label1.Text = "Fri"
            ElseIf DateTime.Now.ToString("dddd") = "Sat" Then
                Label1.Text = "Sat"
            Else
                Label1.Text = Nothing
            End If
        End Sub
    But after 23:59:59, label1.text doesn't change to the next day.
    any suggestions ?

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,546

    Re: Problem with DateTime.Now.ToString

    What's with all that code?

    vb.net Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2. Label1.Text = DateTime.Now.ToString("ddd")
    3. End Sub

  3. #3
    Junior Member
    Join Date
    May 11
    Posts
    26

    Re: Problem with DateTime.Now.ToString

    Quote Originally Posted by dunfiddlin View Post
    What's with all that code?

    vb.net Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2. Label1.Text = DateTime.Now.ToString("ddd")
    3. End Sub
    You are right, I don't need all that code to show the day, I need it like this :
    vb.net Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2. If Label1.Text = "DAY-OF-WEEK1" then
    3. --do-whatever1
    4. ElseIf If Label1.Text = "DAY-OF-WEEK2" then
    5. --do-whatever2
    6. End
    7. End Sub
    Thanks!

    What I actually need is this :
    If Time-and-Date = Time-and-Date in the DB then tell Asterisk to call Extension xxx > play a 5sec beep > hangup
    I'm trying to write a School Bell System that interacts with Asterisk PBX...

  4. #4
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 05
    Location
    Lansing, MI; USA
    Posts
    3,788

    Re: Problem with DateTime.Now.ToString

    Check out the DateTime.DayOfWeek property.
    vb Code:
    1. Select Case DateTime.Today.DayOfWeek
    2.     Case DayOfWeek.Monday
    3.     Case DayOfWeek.Tuesday
    4.     Case DayOfWeek.Wednesday
    5.     Case DayOfWeek.Thursday
    6.     Case DayOfWeek.Friday
    7. End Select
    How do you have the times stored in the DB?
    Currently using: VS 2010 Ultimate on Win7 Ultimate x64.



    CodeBank: All Threads • Colors ComboBox • Fading & Gradient Form • MoveItemListBox/MoveItemListView • MultilineListBox • MenuButton • ToolStripCheckBox • Start with Windows

  5. #5
    Junior Member
    Join Date
    May 11
    Posts
    26

    Re: Problem with DateTime.Now.ToString

    This did the trick :
    Code:
    Label1.Text = DateTime.Now.ToString("ddd")
    the label is changing.
    Thanks

    so it is like this :
    Code:
    if label1.text = Mon or Tue or Wed or Thu then '(day of week)
    goto a #Region for M-T
    ElseIf label1.text = Fri then
    goto a #Region for Fri
    In the #Region there will be a database roe times...

    Quote Originally Posted by JuggaloBrotha View Post
    How do you have the times stored in the DB?
    I don't have a database yet...
    That will be a challenge...

    Do you have any suggestions ?

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,546

    Re: Problem with DateTime.Now.ToString

    Is there anything more to go in than 2 schedules eg.

    Normal, 09.00, 10.00, 11.00 etc.
    Friday, 09.10, 10.00, 11.00 etc. ?

    If not I'm not sure I'd even bother with a database. A simple text file would be more than adequate (and easily edited) with the advantage that you have complete control over the formatting.

  7. #7
    Junior Member
    Join Date
    May 11
    Posts
    26

    Re: Problem with DateTime.Now.ToString

    Quote Originally Posted by dunfiddlin View Post
    Is there anything more to go in than 2 schedules eg.

    Normal, 09.00, 10.00, 11.00 etc.
    Friday, 09.10, 10.00, 11.00 etc. ?

    If not I'm not sure I'd even bother with a database. A simple text file would be more than adequate (and easily edited) with the advantage that you have complete control over the formatting.
    It is not that simple, there is 4 or 5 groups of bell times
    Or maybe you are right, like this:
    if time = 09:00 page group 1 (with class 1>6)
    if time = 09:30 page group 2 (with class 6>10 and outside)

  8. #8
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 05
    Location
    Lansing, MI; USA
    Posts
    3,788

    Re: Problem with DateTime.Now.ToString

    Quote Originally Posted by threeeye View Post
    It is not that simple, there is 4 or 5 groups of bell times
    Or maybe you are right, like this:
    if time = 09:00 page group 1 (with class 1>6)
    if time = 09:30 page group 2 (with class 6>10 and outside)
    What I would do is create an Access database that has 2 columns: Integer (for the day of the week; Sunday is 0, Saturday is 6), Text (to hold the time, I would recommend the time portion use 24 hour time to make things easier). Then I would fill it with each of the day's times the "bell" should ring. For example if the bell rings at 8am M-F, 9am M, W, F and so on there would be these records in the table:
    1,08:00
    1,09:00
    2,08:00
    3,08:00
    3,09:00
    4,08:00
    5,08:00
    5,09:00

    Then when you query that table to get the times for that particular day, just pass it the DateTime.Now.DayOfWeek (which is an integer) and you'll get the times for that day.
    Then it's just a matter of having a timer (tick interval set to 5000 (5 seconds)) and check the time against your list of times, if it matches one of them, then "ring" the bell.

    By using a database, you can more easily incorporate a form that lets you change that "schedule" in the database, you could even include 2 date fields to have different schedules for date ranges (summer classes vs fall classes) and so on.
    Currently using: VS 2010 Ultimate on Win7 Ultimate x64.



    CodeBank: All Threads • Colors ComboBox • Fading & Gradient Form • MoveItemListBox/MoveItemListView • MultilineListBox • MenuButton • ToolStripCheckBox • Start with Windows

  9. #9
    Junior Member
    Join Date
    May 11
    Posts
    26

    Re: Problem with DateTime.Now.ToString

    Quote Originally Posted by JuggaloBrotha View Post
    What I would do is create an Access database that has 2 columns: Integer (for the day of the week; Sunday is 0, Saturday is 6), Text (to hold the time, I would recommend the time portion use 24 hour time to make things easier). Then I would fill it with each of the day's times the "bell" should ring. For example if the bell rings at 8am M-F, 9am M, W, F and so on there would be these records in the table:
    1,08:00
    1,09:00
    2,08:00
    3,08:00
    3,09:00
    4,08:00
    5,08:00
    5,09:00

    Then when you query that table to get the times for that particular day, just pass it the DateTime.Now.DayOfWeek (which is an integer) and you'll get the times for that day.
    Then it's just a matter of having a timer (tick interval set to 5000 (5 seconds)) and check the time against your list of times, if it matches one of them, then "ring" the bell.

    By using a database, you can more easily incorporate a form that lets you change that "schedule" in the database, you could even include 2 date fields to have different schedules for date ranges (summer classes vs fall classes) and so on.
    That is a good idea, but I don't know enough VB.NET A. to call 2 columns in a database, B. I have the following command :
    Code:
    phoneCall = Me.softPhone.CreateCallObject(phoneLine, labelDialingNumber.Text)
    where "labelDialingNumber.Text" is the label with a group to "RING-A-BELL"
    so before the "1,09:00" bell(before every bell, but i took this as e.g.) the "labelDialingNumber.text" needs to change to that bell...

  10. #10
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 05
    Location
    Lansing, MI; USA
    Posts
    3,788

    Re: Problem with DateTime.Now.ToString

    Quote Originally Posted by threeeye View Post
    That is a good idea, but I don't know enough VB.NET A. to call 2 columns in a database, B. I have the following command :
    Code:
    phoneCall = Me.softPhone.CreateCallObject(phoneLine, labelDialingNumber.Text)
    where "labelDialingNumber.Text" is the label with a group to "RING-A-BELL"
    so before the "1,09:00" bell(before every bell, but i took this as e.g.) the "labelDialingNumber.text" needs to change to that bell...
    Here's an example of what I was talking about with using a database for this. I used an Access 2003 database (you can use Access 2010 to edit it, just keep it in the 2002/2003 database format) to hold the data in a single table. I did my best to cover all the basics to it, you'll probably want a different edit form though, but mine at least works to get the point across.

    Also it doesn't take into account where to put the database if you deploy the app (I usually have the app copy the database from the same directory into the current user's appdata folder).
    Also, you'll have to plug in the code you have that actually "rings" the bell too, the app right now just displays a messagebox to indicate when the ringing happens.
    Attached Files Attached Files
    Currently using: VS 2010 Ultimate on Win7 Ultimate x64.



    CodeBank: All Threads • Colors ComboBox • Fading & Gradient Form • MoveItemListBox/MoveItemListView • MultilineListBox • MenuButton • ToolStripCheckBox • Start with Windows

  11. #11
    Junior Member
    Join Date
    May 11
    Posts
    26

    Re: Problem with DateTime.Now.ToString

    Hi,
    This is small and simple, I love it !
    The hard part is to connect it with Asterisk PBX
    The code that I'm working on is a modified softphone that I found...
    There is a lot of files, dll's and "Imports"
    Code:
    Imports System
    Imports System.Net
    Imports System.Net.Sockets
    Imports Ozeki.Media
    Imports Ozeki.Network.Nat
    Imports Ozeki.VoIP.Media
    Imports Ozeki.Media.MediaHandlers
    Imports Ozeki.VoIP
    Imports Ozeki.VoIP.SDK
    Imports Ozeki.Common
    Under the "Ozeki.anything" there is a green zigzag line and a red error
    "Namespace or type specified in the Imports 'Ozeki.anything' doesn't contain any public member or cannot be found..."
    I tried copying the dll's and files, but nothing
    Here is a link with the original softphone and the one I modified.

    https://docs.google.com/open?id=0Bwt...FpFYlpBUGZNSkE

    Thank again

  12. #12
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,546

    Re: Problem with DateTime.Now.ToString

    Project > Add Reference

    You can't import something that the IDE's never heard of!

  13. #13
    Junior Member
    Join Date
    May 11
    Posts
    26

    Re: Problem with DateTime.Now.ToString

    Quote Originally Posted by dunfiddlin View Post
    Project > Add Reference

    You can't import something that the IDE's never heard of!
    THANKS !

    In the next couple days I won't have a lot of time building this pet project (school is starting soon, and I have a lot of work ahead...)
    I'll check back in a few days with an update...

    Thanks again.

Posting Permissions

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