
|
Home Blog Me Funbox Photo Gallery Entertainment Scripts Tutorials Programming Fundamentals Programming in C++ Visual BASIC Programming Part 1 Part 2 Part 3 Part 4 Part 5 Horoscope Writing Site Center Links/Blogrolls Living Room Furniture |
You should be looking at the Visual BASIC IDE with a gray box in the left hand corner. As mentioned previously, this gray box is known as a form. With the form selected, go into the properties window and change the (Name) property to frmMain and change the Text property to Hello. To change these properties, first find them on the left hand side of the Properties Window, then on the right is where you would enter the new values. The (Name) property for items is how we reference them when programming, whereas the Text property is the text that's shown. In your Toolbox, make sure you're displaying All Windows Forms. Click on label and then click and drag in your form to bring it there (you could have also double clicked on the word label). Change the label's Name property to lblHello and the Text property to nothing. (Note: we only change Now go back to the toolbox and add a button. Change the text property of Button1 to Click Me and the Name property to btnClick. Double click on the button you just added, and you will be in Code View. Your cursor should be in the btnClick_Click event procedure (an event procedure is when something happens to the object for example when you click the button this will happen). Making sure you are between the Private Sub and the End Sub, type lblhello.text="Hello" The whole code should look like this:
The word sub indicates that this is a subprocedure, subroutine, or module. Because of this, variables declared or changed in here won't be accessible to other subroutines unless we tell it to be. The line of code that has blHello.Text = "Hello", is common in Visual BASIC. Every component in Visual BASIC is an object and therefore must be referenced as that. You will notice that lblHello is the name you gave it, whereas the .Text is how we reference the other properties of that particular object. There are multiple events for every type of object. If you don't want to use the default event, then while in Code View, click above the code on the dropdown boxes. The one to your left will be the components on your form, while the right one will be which event procedures can exist with that component. ![]() Press F5 or go to Debug/Start Debugging. When you run the program, click the button and the label should say Hello. If it doesn't work, or you get any syntax errors, you may have named something wrong, or types something incorrectly. Make sure you have followed the directions exactly. When we name a component, we use a predefined prefix (lbl for Label, btn for button) to distinguish it from a variable. Here is a list of the some of the most common components, their identifiers, and what they are used for:
Visual BASIC is nice because there are already a lot of objects that are created for us to use. What's also nice is that most of these objects use a lot of the same properties. Here's a list of the commonly used components and what they're used for:
There are other properties, but these are the ones you will most likely be dealing with when working with Visual BASIC. Most of them can be changed at runtime, (using the method shown before, changing the text of the label with the button) but the peoperties in parenthesis can only be changed at design time (the mode you are in when adding components to the form. Next Section: Comments and Variables |
Copyright © 2004-2009 Sean Noble, All rights reserved
Read our Disclosure Policy



