|
|
Join the Discussion |
If
your two button form doesn't work, let's find out why in
the discussion forum.
Discussion Forum
|
|
 |
In the previous page, we actually completed the design of the form
for our project ... which only consisted of dragging two command buttons
to the form. In this page, we change their names, add the event code for
both buttons and actually run the program.
Steps 4 and Step 5
Click the first Command Button to
select it. Open the property window and change the
Name property to
CommandA. Change the
Caption to
A.
Select the second Command Button
from the drop down window at the top of the property window and then
change the Name property to
CommandB. Change the
Caption to
B.
The new thing in this step is 'Open the property window'. Remember
the 'right click context menu' from the previous page? Try right
clicking the first command button and you will see ...
Click 'Properties' at the bottom to open the window. Then click the
'Name' property in the first column and change the value in the second.
We do this because we want to use unique names in our program code to
refer to this object. Visual Basic will do it automatically (it already
has) but it's hard to keep track of a series of objects with names like
'Command1', 'Command2', and so forth. You might also notice that the
Property window is dockable and resizable. It's been undocked and
resized below:
Steps 6, 7, 8, and 9
Double click the first 'Command Button' object in the form to open the
code window for that button.
Enter the code,
Msgbox "You clicked Button A"
after the automatically entered code
Private Sub CommandA_Click()
Double click the second 'Command Button' object in the form to open the
code window for that button.
Enter the code,
Msgbox "You clicked Button B"
after the automatically entered code
Private Sub CommandA_Click()
Notice that a subroutine has already been entered into the code
window automatically. VB 6 helps out as much as it can! All you have to
do is enter your code inside the subroutine. It's worth knowing that all
of the code is actually saved in the form object. VB has to
organize the files for your project and that just happens to be where it
is. If you have independent module code (code that might be used
anywhere your program, rather than just for one particular object and
event), it's saved in a different object. Another thing to notice is the
'naming convention' used for the subroutine:
CommandA_Click
This is always the same. The first part is the name of the object.
The second part is the event. You can't change this name or VB won't
know where to find your event code. Let VB assign these names and leave
them alone.
Steps 10 and 11
Click the 'Run' button in the toolbar at the top of the VB 6 development
environment window to execute the program.
Click either button A or button B and observe the fruits of your labor!
The only confusion factor here might be, "Where is this 'Run'
button?" The answer is, "Right Here ..." (You can also find this on the
'Run' menu.)
If you still think you need some more help getting up to speed, check
out some of the other web pages in the links on the next page. |