Controls and Properties / Properties vs. Methods
Subtitles of the Movie
Up to this point we have been focusing on controls and their properties. I now want to take a look at a button control and its properties but also a method that is typically associated with a button. I also want to use this opportunity to introduce a Visual Basic keyword that is referred to as Me. Quite simply, the word Me in Visual Basic is a shortcut for the current form in the project. Later when we talk about multiple forms this will have more implications, but right now anytime you see the word Me or reference the word Me, it is simply referring to the current form. If I were to drag a button onto the form and first renaming that button to Close Button because the purpose of this button is going to be to close the application and re-caption the text property to Exit the Project or whatever message you would want to give the user, I now am identifying a button that can be used to close the current form. The two properties we just changed, name and text, are indeed properties and we've explored other properties as well. But now if I double click this button to expose the event procedure for the close button and I close the property window to allow us more room, I can write some code, I will begin by writing a simple comment that says ÒThis will close the form.Ó And the code I need is very simple. The word Me.close, close is what's referred to as a method, close is an action verb it does something, so this very simple statement does a very powerful thing, it closes the project. Again, Me refers to the current form, close will close the form. Don't be concerned about the parenthesis that you see after the word close at this point, we'll discuss the meaning and purpose of that later. But at this time, let's just see how this simple line of code will indeed perform its function. Program is now running, my only choice is to select Exit the Project as you can see it causes the program to stop running. As we move further in this course it will be very important to have a good understanding of the difference between a property and a method. Quite simply, a property, available through the properties window are settings that affect the look and size and position of the various controls. It is important to note that not all controls share the same properties. Many properties are found in multiple controls but not all. On the other hand, a method is something that you'll reference in code that causes some action to occur. As we move further, methods become more and more of a vital part of the programming process in Visual Basic 2005.
Tutorial Information
| Course: | Microsoft Visual Basic 2005 |
| Author: | Arthur Lee |
| SKU: | 33940 |
| ISBN: | 1-935320-10-6 |
| Release Date: | 2008-11-19 |
| Duration: | 7.5 hrs / 97 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 