• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Help with A Mesage Box Problem

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
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
7. Above the function you added in the previous step, add the following Sub.

Sub DisplayTime()
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.


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!!!
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.


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


Sub DisplayTime()
End Sub

(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

Hello, is there anybody in there? Just nod if you can hear me ...
What a long strange trip it's been. =)

Forum statistics

Latest member