0% found this document useful (0 votes)
56 views

Exercises

The document provides examples of code snippets and explanations of what the output would be. It also includes exercises asking the reader to identify errors in code or write code to perform certain tasks like calculating prices or distances.
Copyright
© © All Rights Reserved
0% found this document useful (0 votes)
56 views

Exercises

The document provides examples of code snippets and explanations of what the output would be. It also includes exercises asking the reader to identify errors in code or write code to perform certain tasks like calculating prices or distances.
Copyright
© © All Rights Reserved
You are on page 1/ 2

Extra Exercises

In Exercises 1 through 6 , determine the output displayed in the text box or list box by the lines of code.

1. txtBox.Text = "Visual Basic"

2. Dim var As String


var = "Bert"
txtBox.Text = var

3. Dim var As String


var = "Ernie"
lstBox.Items.Add(var)

4. lstBox.Items.Add("a" & "cute")

5. Dim s As String, n As Integer


s = "trombones"
n = 76
txtBox.Text = n & " " & s

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))

In Exercises 7 through 11 , identify any errors.

7. Dim hiyo As String


hiyo = "Silver"
txtBox = "Hi-Yo " & hiYo

8. Dim num As Double = 1234


txtBox.Text = CStr(num.IndexOf("2"))

9. Dim num As Integer = 45


txtBox.Text = CStr(num.Length)

10. Dim m As Decimal, n As Integer


m=2^3
n=4/2

11. Dim m As Decimal, n As Integer


m=

12. PRICE OF KETCHUP The following steps compute the price of ketchup:
a. Declare the variable item as type String. Declare the
variables regularPrice and discount as type Decimal.
b. Assign “ketchup” to the variable item.
c. Assign 1.80 to the variable regularPrice.
d. Assign .27 to the variable discount.
e. Assign to the variable discountPrice the expression
(NOTE: The product is 1.53.)
f. Display the sentence “1.53 is the sale price of ketchup.”

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.

Possible outcome of Exercise 13

You might also like