Visual Basic ... A Basic Tutorial (EX2)
This is the second exercise in my attempt at a tutorial! Please dont flame me much i trying my hardest :D
Exercise 2 : Hello Project
Remember : Each New Project Should Be Saved In A New Folder
1) Create a new folder in which to save this project, e.g c:\Hello
2) On a new form, draw one label and three command buttons and set the following properties:
Command Button1:
Name = cmdDisplay
Caption = Display
CommandButton2:
Name = cmdClear
Caption = Clear
Enabled = False
Command Button3:
Name = cmdExit
Caption = Exit
Label:
Name = lblMessage
Caption = (leave Blank)
Font Size = 14
Form:
Name = frmGreetings
Caption = Greetings!
2) There are three events possible here:
- the cmdDisplay button is clicked
- the cmdClear button is clicked
- the cmdExit button is clicked
so you must attach code to each button.
When the Display button is clicked we want to:
Display 'Hello Pat' in the label, lblMessage
Make the clear button enabled (so user can click it)
Make the Display button disabled (so user cant click it)
so, attach this coding to the display button:
Sub cmdDisplay_Click()
lblMessage.Caption = "Hello Pat"
cmdClear.Enabled = True
cmdDisplay.Enabled = False
End Sub
3) Attach similar coding to the clear button, so that the following will happen when it is clicked:
Display nothing in the label, lblMessage
Make the Display button enabled (So user can click it)
Make the clear button disabled (So user cant click it)
Work this out for yourself :-P
HINT: code it between
Sub cmdClear_Click()
End Sub
4) Attach code to the exit button so that the program will end when this button is clicked:
Sub cmdExit_Click()
End
End Sub
5) Run your program and see what it does
6) Use save project as to save the project to the folder you created in step 1