|
-
Mar 11th, 2010, 04:58 PM
#1
Thread Starter
Addicted Member
[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" 
-
Mar 11th, 2010, 05:21 PM
#2
Re: Problem with Date and Time module
Replace this:
lbldat.Text = DateAndTime.Now.ToString
with this:
lbldat.Text = Now.ToString
-
Mar 11th, 2010, 07:37 PM
#3
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.
-
Mar 12th, 2010, 03:56 PM
#4
Thread Starter
Addicted Member
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" 
-
Mar 12th, 2010, 09:36 PM
#5
Re: Problem with Date and Time module
 Originally Posted by Pantero
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.
-
Mar 12th, 2010, 10:14 PM
#6
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
-
Mar 13th, 2010, 05:23 AM
#7
Thread Starter
Addicted Member
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" 
-
Mar 13th, 2010, 05:26 AM
#8
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.
-
Mar 17th, 2010, 03:37 PM
#9
Thread Starter
Addicted Member
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" 
-
Mar 17th, 2010, 03:53 PM
#10
Re: Problem with Date and Time module
Depends... when do you want it to start?
-tg
-
Mar 17th, 2010, 04:36 PM
#11
Thread Starter
Addicted Member
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" 
-
Mar 17th, 2010, 06:43 PM
#12
Re: Problem with Date and Time module
 Originally Posted by Pantero
When the form starts.. So I guess in the form_load procedure..?
That would be my guess also.
-
Mar 18th, 2010, 10:37 AM
#13
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|