VB Use Update
VB Use Update
Programming
With
VB.NET
UNIT 1
Exercise 1.0
2i
UNIT 2
Exercise 2.0
18i
Exercise 2.1
Build and test the application in this session and assign a student’s name to the Text
property of the Textbox control named NameTextBox and a student’s department to
the textbox control named MajorTextBox.
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
18ii
Exercise 2.2
1. A: …………………………………….
2. B: …………………………………….
3. C: …………………………………….
4. D: …………………………………….
A: …………………………………………………………………………………………
B: …………………………………………………………………………………………
C: …………………………………………………………………………………………
D: …………………………………………………………………………………………
18iii
UNIT 3
Exercise 3.0
Fill in the blank spaces in below in regards to Flowchart.
……………….. …………………………………………………………
…………………………………………………………
………………… …………………………………………………………
………………… …………………………………………………………
……………….. …………………………………………………………
…………………………………………………………
……………….. ………………………………………………………………
………………………………………………………………
……………….. ………………………………………………………………
………………………………………………………………
…………………………………………………………
………………..
…………………………………………………………
………………………………………………………………
………………..
………………………………………………………………
31i
Exercise 3.1
Write a program that computes the sum of two numbers and displays the result in
another textbox.
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
31ii
Exercise 3.2
The cost of the electricity used by a device is given by the formula;
Cost of electricity = wattage of device * hours used * cost per kW / 100, 000
where kWh is an abbreviation for “kilowatt hour.” The cost per kWh of electricity varies
with locality. In 2018, the average cost of electricity for a residential customer in Ghana
was 12¢ per kWh. Write a program that allows the user to calculate the cost of
operating an electrical device.
Possible Outcome
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
……….................................................................................................................................
31iii
UNIT 4
Exercise 4.0
The flowchart below calculates a person’s income tax. Write a program corresponding
to the flowchart.
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
39i
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
39ii
Exercise 4.1
Write a program that requests your date of birth as input and tells whether or not you
are 25 years old or older. If not, the program should tell you the number of days until
you will have your 25th birthday.
Possible outcome
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
38iii
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Exercise 4.2
A clothing store advertises “BUY 2 ITEMS AND THE 3 IS FREE.” What they mean is
that if you buy three items, then the lowest cost item is free. Write a program that
accepts the three costs as input and then calculates the total cost after dropping the
lowest cost.
Possible outcome
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
39iv
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
39v
Extra Exercises
In Exercises 1 through 6 , determine the output displayed in the text box or list box by the lines of code.
6. Dim m As Integer = 4
Dim n As Integer = 3
Dim s As String = "Microsoft"
Dim t As String = "soft"
lstOutput.Items.Add(s.Length)
lstOutput.Items.Add(s.ToLower)
lstOutput.Items.Add(s.Substring(m, n − 1))
lstOutput.Items.Add(s.IndexOf(t))
13. DISTANCE FROM A STORM If is the number of seconds between lightning and thunder, the storm
is /5 miles away.
Write a program that reads the number of seconds between lightning and thunder and reports the
distance of the storm rounded to two decimal places.