Help with A Mesage Box Problem

Joined
Dec 7, 2006
Messages
1
#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
Dec 26, 2006
Messages
1
#2
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 posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,979
Messages
673,325
Members
89,020
Latest member
Amanda99