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