Help with A Mesage Box Problem

steevc

Steve
Joined
7 Dec 2006
Messages
1
I really hope you can help!!! I’ve been trying to figure this out for 2 weeks!! (I’m a beginner).
Here is an extract from a VB tutorial:

To create procedures
1. On the File menu, choose New Project.
2. In the New Project dialog box, in the Templates pane, click Windows
Application.
3. In the Name box, type MyFirstProcedure and then click OK.
A new Windows Forms project opens.
4. Double-click the form to open the Code Editor.
5. In the Code Editor, locate the line that reads End Class. This is the end of
the code section that makes up your form. Immediately before this line, add
the following procedure:

Function GetTime() As String
Return CStr(Now)
End Function

6. This function uses the built-in Now procedure to get the current time, then
uses the CStr function to convert the value returned by Now into a humanreadable
String. Finally, that String value is returned as the result of the
function.
7. Above the function you added in the previous step, add the following Sub.

Sub DisplayTime()
MsgBox(GetTime)
End Sub

8. This sub calls the function GetTime and displays the result returned by it in a
message box.
9. Finally, add a line to the Form1_Load event handler that calls the
DisplayTime sub, as shown below.

DisplayTime()

10. Press F5 to run the program.
---------
So far so good!

What I’d like to do is substitute a form (with a label) in place of the message box. I made a form and put a label on it, but I’ve tried many combinations and I can’t work out what I’m doing wrong – I get the error message: “Property access must assign to the property or use its’ value”.
I’d like to work out how to do 2 things here:
1, Open the form and have a button on it so that pressing the button will show the date/time in the label control (ie on same form) and
2, operate the "displaytime" procedure and my new “date/time” form opens, with the date showing in the label control.
I worked out that I can’t just replace “msgbox” with the name of my new form, other than that, I’m out of ideas! I’d really appreciate someone’s help, I’m pulling my hair out in frustration!!!
Regards,
Steve
 

PeterMorano

Helpful Coder
Joined
26 Dec 2006
Messages
1
I find that people new to using VB often get stuck on the little things that later will have you saying 'i can't believe i missed that'. Can you send me the code, or put a little bit more of it here? I think I might be able to spot the problem right away if I saw the code. If you email, send it to peter at petermorano dot com.

-edit-

After rereading your message, I think this is the soluton:

Change

Sub DisplayTime()
MsgBox(GetTime)
End Sub

To
(assume you named the Label to lblCurrentTime):

Sub DisplayTime()
lblCurrentTime.Caption = GetTime()
End Sub

Let me know if that does the trick.
 
Last edited by a moderator:

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,013
Messages
673,483
Members
5,607
Latest member
jonazop