Visual Basic 2008 Programming: Business Applications with a Design Perspective
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9
Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Appendix A Appendix B Appendix C Home
Loading
Last change: February 13 2016 18:48:19.

 Chapter in PDF

Chapter 2: Visual Basic Programming Concepts
Last change: February 13 2016 18:48:07.
<<PreviousNext>>

Changing the Object Names in the Project

To implement the aforementioned naming standard in your Welcome example project, follow these steps:

  1. Change the button name to lblbtnWelcome. You can do this by using the Properties window. Do the following:
    1. Click the label in the form.
    2. Select the Name property in the Properties window. The Name property appears near the top of the Properties list in both Categorized and Alphabetic views.
    3. Type lblWelcome in the box.
    It is a good habit to test the program whenever a change is made. After you have changed the label name, start the project by clicking the Start button. The program should run without any problem.
  2. Change the name of the button to btnWelcome; then start the project, and click the button. Again, the program runs without any problem. If you inspect the code, you will notice that a part of the Button1_Click line has been changed. Previously, at the end of the line, it had Handles Button1.Click. Now, however, it shows Handles btnWelcome.Click.  Also, you should notice that the code line that begins with Label1.Text has now been changed to lblWelcome.Text! This IDE feature of automatic correction saves the programmer a lot of troubles. Previous versions did not have this feature and required the programmer to correct the code each time an object name in the code has been changed. In spite of this convenience, it is still advisable that before any code is written, all objects to be referred to in the code be named. In this example, you still see that the first part of the line Private Sub Button1_Click remains the same, introducing some element of confusion. For clarity and ease of review in the future, you should replace Button1 in the procedure header to btnWelcome. The corrected event procedure should appear as follows:

    Private Sub btnWelcome_Click(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles btnWelcome.Click 'Make the label display thee Welcome message lblWelcome.Text = "Welcome to Visual Basic!!!" End Sub

     
  3.    
  4. Change the name of the form to frmWelcome and then run the program again. It should run without any problem.
Tip
When developing a project, always make sure that all objects have been named properly before starting to place any code in the code window. This helps to eliminate the possibility of confusion or encountering mysterious errors in code associated with the names.
Last change: February 13 2016 18:48:07.
<<PreviousNext>>