Friday, July 9, 2010

1.2 Textboxes Command Buttons Labels and Listboxes - VB6

TextBoxes - These are possibly the most common objects you will use in VB. Basically, anytime the user needs to input data into the program, you will use a textbox. For example, if the user needs to type in a user name and password, he would type it in a textbox. To create a textbox, go to the left hand tool bar and click this icon.

Go to the form. Click and drag the textbox to as big as you want it to be. Once created, name the textbox with a name starting with "txt". You can also change what the actual text is by changing the text property.
If you wanted to later change the text inside a textbox, you would use the code
Code:
txtNAMEOFTEXTBOX.Text = "whatever you want"

Command Buttons - Command buttons are exactly what they sound like, buttons that do commands. Anytime you want an action preformed at the users request, use a command button. For example, if on the click of a button you want to erase the text in a form, or log in, you would use a command button. To make a command button, go to the left hand bar and click the command button icon.

Go to the form. Click and drag until the button is the size you want it to be. Make sure you name command buttons starting with "cmd". Another property you will often use is the 'Caption' property, which changes the text that is displayed on the button. To write the code that the button will do, double click the button on the form. A code window should pop up, and the cursor should be in the appropriate place.

Labels - Labels are...labels. They are used when you want to label anything such as a textbox, or a listbox. You can even use a label as a status bar. Like the other elements, click the label button on the left hand bar, and draw it onto the form.

Label's names should start with "lbl". To change what you want the label to say, use the caption property, or if you want to change the label's text while the program is running, use code like this
Code:
lblNAMEOFLABEL.Caption = "whatever you want"
Other label properties that can be changed are the background, text colors, font, and many more.

Listboxes - A listbox is almost exactly like a textbox, except that it cannot be directly edited, and that a listbox has an infinate amount of lines. Each line of the listbox is treated as its own textbox. Listboxes are very often used as a log for programs. To create a listbox, go to the left hand toolbar, select the listbox icon, and draw it on the form.

Name all listboxes starting with "lst".
Ex. lstNAMEHERE
Some handy code to know with a listbox is how to add an item to the list. To do this use this code:
Code:
lstNAME.AddItem "whatever"



Download .doc & .pdf versions here:
http://www35.zippyshare.com/v/95632623/file.html

0 comments:

Post a Comment