Visual Basic Lab: First Program
This lab uses: Text box, Command buttons, Check boxes, Option buttons, Color
Create a new Visual Basic program.
- Set the Caption property for Form1 to "VB Lab 1".
- Put a Text Box
control on the form. Set the following properties for Text1:
Text = ACME
Fonts: FontName = Times New Roman, FontSize = 16
BorderStyle = 0-none, Multiline = True
Left = 120, Top = 1560, Width = 2055,Height = 855
(The four dimensions are in "twips", or "twentieths of a point". 72 points = 1 inch. 1440 twips
= 1 inch. )
- Draw a Command
Button control on your form. Set the following properties for Command1:
Caption = ACME
Left = 120, Top = 3120, Width = 855, Height = 375
- Draw two more Command Buttons the same size as Command1, just below Command1.
For Command2, set its Caption property to "Author"
Set Command3's Caption property to "Exit"
- Double-click on Command1 to open the code window for its Click event. Enter the following command:
Text1.Text = "ACME"
- Program Command2's Click event to put your name in the Text box.
- Program Command3's Click event to exit the program with the command: End.
Try running the program. It should work as advertised.
- From the File menu, choose "Save Project". You will be prompted for a name for the
form file. Try something like "a:first". The extension .FRM will be added automatically. You will
then be prompted for a name for the project file. Use "a:first" again, but this time the extension .VBP
will be added automatically.
- Add a Check
Box control to your form. Set the following properties:
Caption = Bold
Left = 1080, Top = 3120, Width = 1335, Height = 255
- Add another Check Box the same size as Check1, just below Check1. Set its Caption
- Double-click on the Check Box with the Caption "Bold" to open the code window for its
Click event. Put in the following line of code:
Text1.FontBold = Check1.Value
Repeat for the other Check Box, but alter the Text box's FontItalic property instead.
Save the project, then try running your program again.
- Click anywhere on Form1 where there is not a control, and look at its properties list. Double-click
on the Picture property. From the "Load Picture" dialog box, find and select the file COYOTE.BMP
(if you are at ECC, look in the directory I:\MARKP\DATA\VB).
here to download the file COYOTE.BMP (7Kb zipped)
- Find the Icon property for Form1, and double-click on it. From the "Load Icon"
dialog, look in the \VB\ICONS\MISC directory, and select the file MISC39A.ICO.
- Add four Option
Button controls to your form. Make their captions "Red", "Green", "Blue", and
"Yellow". Put the following code in the Option1_Click event:
Text1.ForeColor = RGB(255,0,0)
Program the Click events for Option2 and Option3 to give green and blue text. Try experimenting
with the RGB function for Option4.
- From the File menu, choose "Make EXE file" to compile your finished program into a
separate executable file. This lab example does not have to be sent to the instructor. When you finish assignment
1, even though you can create an EXE file, you will be zipping together your project and form files and sending
those instead. That way we can see how you wrote your program, not just the results.
to this lessonCourse Index ©1996-2000, Mark Pelczarski