Lab01
description
Transcript of Lab01
![Page 1: Lab01](https://reader031.fdocuments.us/reader031/viewer/2022021301/563db9e8550346aa9aa100f9/html5/thumbnails/1.jpg)
7/17/2019 Lab01
http://slidepdf.com/reader/full/lab01-5690ef018c790 1/5
BPB2034 Programming For Business Applications
1
Lab 1Step by step to write your first Visual Basic program
1. Go to: Start → All Programs → Microsoft Visual Studio 2012 Express → VS Express
for Desktop
2. Click on File → New Project → Windows Forms Application.
Name: Name given to your project.Location: Where you want to save your project related files (e.g.: source files, resources,
etc)
![Page 2: Lab01](https://reader031.fdocuments.us/reader031/viewer/2022021301/563db9e8550346aa9aa100f9/html5/thumbnails/2.jpg)
7/17/2019 Lab01
http://slidepdf.com/reader/full/lab01-5690ef018c790 2/5
BPB2034 Programming For Business Applications
2
3. Expand the Common Controls from the Toolbox panel. Select Label control and drag and
drop on the Windows form, as shown below:
4.
Next, select the Button control and drop it on the Windows form. Alternatively, you candouble click on the Button control in the Toolbox and a new button will be generated and
placed on the form. All the controls on the form will be given with default names, e.g.
Button1, Button2, Label1 and Form1 as for the example as shown above.
5. The controls are generated in default sizes. The control can be easily resized by adjusting
the handle surrounding the control you have selected, just like how you able to resize animage in Microsoft Word.
6.
Moving a control is easy too as well. Move the mouse cursor over the control you would
like to move until you see a cursor, then click and drag and move the control to theintended location on the form.
7. Aligning controls can be done by first performs a multiple selection by holding the SHIFT key on the keyboard and then select the controls. Go to the menu on the top and select
Toolbox Panel
Control’s
properties
“Handle” to adjust
size of the selected
control
![Page 3: Lab01](https://reader031.fdocuments.us/reader031/viewer/2022021301/563db9e8550346aa9aa100f9/html5/thumbnails/3.jpg)
7/17/2019 Lab01
http://slidepdf.com/reader/full/lab01-5690ef018c790 3/5
BPB2034 Programming For Business Applications
3
FORMAT → Align → [Lefts / Centers / Rights / Tops / Middles / Bottoms] (Try to
explore other available options available under FORMAT menu).
8. To avoid a control from being accidentally moved/resized, you can actually “lock” the
control. Select the control and perform the right click to activate the Shortcut menu, then
select the Lock Controls option.
Locking a control Button1 A control Button1 is locked
9. Try to modify Text and Name properties of each control on the form. You are encouraged
to use the three-letter prefixes as practice to name the controls. What is the difference between Text and Name properties?
Three-letter Prefi xes
Object Prefix Example
Form frm frmExample
Button btn btnExit
Label lbl lblMessageList box lst lstNames
Text box txt txtPhone
Object Default Text & Name Text Name
Button Button1 Show Message btn ShowMessage
Button Button2 E&xit btn Exit
Label Label1 Welcome to BPB2034 lbl Message
Form Form1 First VB Program f rm FirstProgram
10. Double-click on the “Show Message” button in order to open the code editor. A sub
procedure will be automatically generated for you to handle the CLICK event. Now, it isyour task to tell the computer what to be done (programming!!!) when a user performs a
click on the “Show Message” button.
Private Sub btnShowMessage_Click(…) Handles btnShowMessage.Click
‘ insert your code between the Sub … End SubEnd Sub
![Page 4: Lab01](https://reader031.fdocuments.us/reader031/viewer/2022021301/563db9e8550346aa9aa100f9/html5/thumbnails/4.jpg)
7/17/2019 Lab01
http://slidepdf.com/reader/full/lab01-5690ef018c790 4/5
BPB2034 Programming For Business Applications
4
In this example, you are required to show a “Hello World” message on the label. Remember
the name given to our Label control: lblMessage? This name will serve as an identifier tothat particular control for us to access and modify various properties of that control.
Private Sub btnShowMessage_Click(…) Handles btnShowMessage.Click
lblMessage.Text = "Hello World" End Sub
11. Similarly, you can provide code for the btnExit button, which will exit the program whenthe button is clicked.
Private Sub btnExit_Click(…) Handles btnExit.ClickApplication.Exit()
End Sub
12. To debug/run your program, click: DEBUG → Start Debugging (or use shortcut key F5).
13. Task 1: Add a new button into frmFirstProgram. Align and adjust the width of the newly
created button with respect to the btnShowMessage button, as shown below:
Identifier Message to be displayedProperty’s Name
![Page 5: Lab01](https://reader031.fdocuments.us/reader031/viewer/2022021301/563db9e8550346aa9aa100f9/html5/thumbnails/5.jpg)
7/17/2019 Lab01
http://slidepdf.com/reader/full/lab01-5690ef018c790 5/5
BPB2034 Programming For Business Applications
5
Modify the Text and Name properties of this new button (Text = “Clear Message”; Name
= “btnClearMessage”). Please attempt to provide code for btnClearMessage button which
will clear the message displayed on the lblShowMessage when such button is clicked.
14. Task 2: Modify btnShowMessage to take message input from the user and then display the
message on lblMessage. [Hint: use InputBox( … ) function]
15. Task 3: Add additional three buttons namely: Red, Blue and Black. Code each button to
change the fore color property of the lblMessage when the button is clicked [Hint: select
predefined color e.g. Color.Red ].
Supplementary Learning Resources:
https://www.youtube.com/watch?v=BzC16c7bXJU
https://www.youtube.com/watch?v=LqltC7nescM