Results 1 to 13 of 13

Thread: [RESOLVED] Problem with Date and Time module

  1. #1

    Thread Starter
    Addicted Member Pantero's Avatar
    Join Date
    Jan 2009
    Posts
    169

    Resolved [RESOLVED] Problem with Date and Time module

    Hi, i've got a module for my program thats displays the active time and date, on a form. For some reason my code is incorrect and nothing happens when I run the form. I can't figure out what the problem is, can anyone help?

    Heres the code I have in the module:

    Code:
    Module ModDateAndTime
    
        'Declares tmrdat as a timer with events
        Public WithEvents tmrdat As Timer
        'declares lbldat as a label
        Public lbldat As Label
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrdat.Tick
            'puts the Time and date into the label 
            lbldat.Text = DateAndTime.Now.ToString
        End Sub
    End Module
    And the code in the form's:

    Code:
    'declares lbldat as lbldateandtime
            lbldat = lblDateandTime
    The relevant label in the form is named lblDateandTime

    Thanks
    Im using visual basic 2008 express edition so any posts that include coding or stuff PLEASE refer to vb 2008.

    "A clever person solves problems, a wise person avoids them"

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Problem with Date and Time module

    Replace this:
    lbldat.Text = DateAndTime.Now.ToString

    with this:
    lbldat.Text = Now.ToString
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with Date and Time module

    Why would you put that functionality in a module? That is straight-up presentation so it belongs in the form itself. You should add the Timer to your form and then in the Tick event handler use:
    Code:
    Me.lblDateandTime.Text = Date.Now.ToString()
    You should use the Date data type rather than the DateAndTime module.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Addicted Member Pantero's Avatar
    Join Date
    Jan 2009
    Posts
    169

    Re: Problem with Date and Time module

    Okay i've spent a rather frustrating 15 minutes finding out that neither method works.
    Both have no errors (when tried separately) yet neither shows the date and time, in the label at all.

    Any suggestions?
    Im using visual basic 2008 express edition so any posts that include coding or stuff PLEASE refer to vb 2008.

    "A clever person solves problems, a wise person avoids them"

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with Date and Time module

    Quote Originally Posted by Pantero View Post
    Okay i've spent a rather frustrating 15 minutes finding out that neither method works.
    Both have no errors (when tried separately) yet neither shows the date and time, in the label at all.

    Any suggestions?
    Both methods work perfectly. Either you're not executing the code or your referring to the wrong Label.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Problem with Date and Time module

    The code that I don't see: Where the timer is create, where its interval is set, and where the timer is started.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Addicted Member Pantero's Avatar
    Join Date
    Jan 2009
    Posts
    169

    Re: Problem with Date and Time module

    I've just tried both methods again, on a completely new project and still neither works, I must be doing something wrong. I don't know what, but the label doesn't change into the 'active' date and time, and i honestly don't know the reason.
    Im using visual basic 2008 express edition so any posts that include coding or stuff PLEASE refer to vb 2008.

    "A clever person solves problems, a wise person avoids them"

  8. #8
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Problem with Date and Time module

    Did you look at techgnome's comment? Unless you start your timer it will never fire the tick event and your code to set the label will never run.

  9. #9

    Thread Starter
    Addicted Member Pantero's Avatar
    Join Date
    Jan 2009
    Posts
    169

    Re: Problem with Date and Time module

    Ah yes, I must have missed techgnome's comment. Quick question: Where would I start the timer, in the module?, each form's load event?, or somewhere else?
    Im using visual basic 2008 express edition so any posts that include coding or stuff PLEASE refer to vb 2008.

    "A clever person solves problems, a wise person avoids them"

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Problem with Date and Time module

    Depends... when do you want it to start?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11

    Thread Starter
    Addicted Member Pantero's Avatar
    Join Date
    Jan 2009
    Posts
    169

    Re: Problem with Date and Time module

    When the form starts.. So I guess in the form_load procedure..?
    Im using visual basic 2008 express edition so any posts that include coding or stuff PLEASE refer to vb 2008.

    "A clever person solves problems, a wise person avoids them"

  12. #12
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Smile Re: Problem with Date and Time module

    Quote Originally Posted by Pantero View Post
    When the form starts.. So I guess in the form_load procedure..?
    That would be my guess also.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  13. #13

    Thread Starter
    Addicted Member Pantero's Avatar
    Join Date
    Jan 2009
    Posts
    169

    Re: Problem with Date and Time module

    Ah, I already had some code in the Timer_Tick event, already and all i needed to do, was to just enable the timer.

    Thanks very much for your help.
    Im using visual basic 2008 express edition so any posts that include coding or stuff PLEASE refer to vb 2008.

    "A clever person solves problems, a wise person avoids them"

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