Intro to Visual Basic - Chapter 5
A loop's conditionally executed statements should be indented.
True
In a For...Next loop, the Counter Variable must be numeric.
True
In a nested loop, the inner loop goes through all of its iterations for each iteration of an outer loop.
True
Infinite loops keep repeating until the program is interrupted.
True
What does a Random object use as its seed value if you do not specify one?
When a random object is created in memory, it retrieves the system time from the computer's inner clock, and uses that as the seed value.
In general terms, describe how a Do While loop works.
When the loop runs, the BooleanExpression is tested. If it is true, then the statements in the body of the loop are executed. Then the loop starts over and the BooleanExpression is tested again. If it is still true, the statements in the body of the loop are executed. This cycle repeats until the BooleanExpression is false
Why should you indent the statements in the body of a loop?
You can quickly see which statements are repeated by the loop because they are indented.
Next Double method
a Random class method that is used to get a random floating-point number between 0.0 and 1.0 (not including 1.0)
Next method
a Random class method that is used to get a random integer number
input box
a Windows dialog box that displays a message to the user; it provides a text box for the user to enter input
Items.Insert method
a list box and combo box method that adds an item at a specific index of the control's Item property
Items. Add
a list box and combo box method that adds an item to the end of the control's Item property
Items.Clear method
a list box and combo box method that erases all the items in the control's Items property
Items.RemoveAt method
a list box and combo box method that removed an item at a *specific index* of the control's Item property
Items.Remove method
a list box and combo box method that removed an item at a specific index of the control's Item property
nested loop
a loop inside another loop
For ... Next loop
a loop specifically designed to initialize, test, and increment a counter variable
infinite loop
a loop that never stops repeating
Do While loop
a looping structure that causes one or more statements to repeat as long as an expression is true
Do Until loop
a looping structure that causes one or more statements to repeat until its test expression is true
component tray
a re-sizable region at the bottom of the Designer window that holds invisible controls
ToolTip control
a small box that pops up when you hover the mouse over a button on the toolbar in the Toolbox; it contains a short description of the button's purpose
Random object
a special type of object that has methods and properties that make generating random numbers fairly easy
running total
a sum of numbers that accumulates with each iteration of a loop
counter
a variable that is regularly incremented or decremented each time a loop iterates
With...End With statement
allows you to create a With block; statements inside a Withblock may perform several operations on the same object without specifying the name of the object each time
repetition structure
also called a loop, causes one or more statements to repeat
Sorted property
causes the items in the Items property of a list box to be displayed alphabetically
This is the prefix that we use for combo box names.
cbo
This control has a rectangular area that functions like a text box.
combo box
A ___ is a variable that is regularly incremented or decremented each time a loop iterates.
counter
ListBox control
displays a list of items and allows the user to select one or more items from the list
What value is returned by the InputBox function if the user clicks the Cancel button?
empty string
post test loop
evaluates its test-expression after each iteration
pre test loop
evaluates its test-expression before each iteration
A pretest loop always performs at least one iteration, even if the test expression is a false from the start.
false
SelectedItem property
holds the currently selected item of a list box or combo box
SelectedIndex property
holds the index of the selected item in a list box or combo box
Items.Count property
holds the number of items in a list box or combo box
loop
one or more programming statements that repeat
A ___ loop evaluates its test expression after each iteration.
post test
This type of loop evaluates its test expression before each iteration.
pre test
A ___ object has methods that can generate a sequence of random numbers.
random
Pmt function
returns the periodic payment amount for a loan
PPmt function
returns the principal payment for a specific period on a loan
IPmt Function
returns the required interest payment for a specific period on a loan
One of the following is a sum of numbers that accumulates with each iteration of a loop.
running total
Visual Basic automatically adds this to a list box when it contains more items than can be displayed.
scroll bar
combo box
similar to list boxes; display lists of items to the user
With this style of combo box, the list of items does not drop down, but is always displayed.
simple combo box
conditionally executed statements
statements that are executed only when certain conditions exist; usually determined by the value of a Boolean expression
Exit Do statement
stops the execution of a Do While or Do Until loop
Exit For statement
stops the execution of a For...Next loop
Assume 1stNames is a list box and strSelectedName is a String variable. Write a statement that assigns the second item in 1stnames to strSelectedName.
strSelectedName = 1stNames.Items(1).ToString()
This combo box property will contain the user's text input or the item selected from the list.
text
What value does a Random object use as its seed if you do not specify a seed value?
the system time from the computer's internal clock
step value
the value added to the counter variable at the end of each iteration of a For...Next loop
accumulator
the variable used to keep a running total
The Do While loop may be written as either a pretest or posttest loop.
true
seed value
used in the calculation that returns the next random number in the series; a value from the system timer is used by default; a value can be specified when creating a Random object.
Describe the difference between pretest loops and posttest loops.
• In a pretest loop, the Boolean expression is tested first. If the expression is true, the loop then executes the statements in the body of the loop. This process repeats until the Boolean expression is false. • In a posttest loop, the statements in the body of the loop are executed first, and then the Boolean expression is tested. If the Boolean expression is true, the loop repeats. If the Boolean expression is false, the loop stops.
Describe the two important parts of a Do While loop.
*a Boolean expression that is tested for a True or False value *a statement or group of statements that is repeated as long as the Boolean expression is true
A list box or combo box's index numbering starts at this value.
0
What is the index of the first item stored in a list box or combo box's Items property?
0
What values will the following code segment add to the 1stNumbers list box? For intX = 1 To 3 1stNumbers.Items.Add(intX) For intY = 1 To 2 1stNumbers.Items.Add(intY) Next Next
1,1,2,2,1,2,3,1,2
If a list box has 12 items stored in it, what is the index of the 12th item?
11
How many times will the value in intY be displayed in the following code segment? For intX = 1 To 20 For intY = 1 To 30 MessageBox.Show(intY.ToString() ) Next Next
600
What feature do combo boxes have that list boxes do not have?
A combo box performs many of the same functions as a list box, and it can also let the user enter text.
Suppose you want to place a list box on a form, but it would take up too much space. What other control might you use?
A drop down list combo box
What does a Random object's NextDouble method return?
A random floating point number between 0.0 and 1.0 (not including 1.0)
What does a Random object's Next method return?
A random integer value somewhere between 0 and 2,147, 483, 647
Why are the statements in the body of a loop called conditionally executed statements?
Because the statements in the body of the loop are executed only under the condition that the Boolean expression is true.
The Do While statement marks the beginning of a Do While loop, and the Loop statement marks the end. The statements between these are known as one of the following.
Body of the Loop
What is the best method of getting the user's input from a combo box?
By retrieving the value in the text property
The following loop adds the numbers 1 through 5 to the 1stOutput list box. Modify the loop so that instead of staring at 1 and counting to 5, it starts at 5 and counts backward to 1. Dim intCount As Integer = 1 Do While intCount <= 5 1stOutput.items.Add(intCount) intCount += 1 Loop
Dim intCount As Integer = 5 Do While intCount >= 1 1stOutput.Items.Add(intCount) intCount -= 1 Loop
Which of the following statements creates a Random object and initializes the sequence of random numbers with the seed value 25?
Dim rand As New Random(25)
Which loop should you use in situations where you wish the loop to repeat as long as the test expression is true?
Do While loop
What is the difference between a drop-down and a drop-down list combo box?
Drop down combo box allows the user to type text into its text area. Drop down *list* combo box does not; you can only select an item from the list
With one style of combo box the Text property is read-only. Which style?
Drop-Down List Combo Box
With one style of combo box the user may not type text directly into the combo box, but must select an item from the list. Which style is it?
Drop-Down List Combo Box
The ___ statement, when placed inside the body of a Do While loop, stops the execution of the loop and causes the program to jump to the statement immediately following the loop.
Exit Do
A drop-down list combo box allows the user to either select an item from a list or type text into a text input area.
False
If the user clicks an input box's Cancel button, the function returns the number -1.
False
If you do not provide a value for an input box's title, and error will occur.
False
The Items.RemoveAt method always removes the lat item in a list box (the item with the highest index value).
False
To create a checked list box, you draw a regular list box and set its Checked property to True.
False
How many times will the code inside the following loop execute? What will be displayed in the message box? intX = 0 Do Until intX = 10 intX += 2 Loop MessageBox.Show(intX.ToString() )
Five times; the message box will display 10
This type of loop is ideal for situations that require a counter because it is specifically designed to initialize, test, and increment a counter variable.
For...next
Which type of loop should you use when you know the number of required iterations?
For...next loop
The ___ function returns the required interest payment for a specific period on a loan.
IPmt
A ___ provides a simple way to gather input without placing a text box on a form
Input box
You display input boxes with this function.
InputBox
What happens if the same seed value is used each time a Random object is created?
It will always generate the same series of random numbers.
Which list box or combo box property holds the number of items stored in the Items property?
Items.Count
Which list box property holds the number of items stored in the Items property?
Items.Count
This method erases one item from a list box.
Items.Remove
A ___ displays a list of items and allows the user to select an item from the list.
ListBox control
A ___ causes one or more statements to repeat.
Loop or repetition structure
You do this to get the total number of iterations of a nested loop.
Multiply the number of iterations of all the loops
The ___ function returns the principal payment for a specific period on a loan.
PPmt
The ___ function returns the periodic payment amount for a loan.
Pmt
If you want a Do While loop always to iterate at least once, which form should you use, pretest or posttest?
Post test
This property box holds the index of the selected item in a list box.
SelectedIndex
Which list box or combo box property holds the index of the item selected from the list?
SelectedIndex
Which list box property holds the index of the item that has been selected from the list?
SelectedIndex
Which list box property holds the item that has been selected from the list?
SelectedItem
An input box returns the value entered by the user as this.
String
Which type of loop is best to use when you want the loop to repeat until a condition exists?
The Do Until loop
Which type of loop is best to use when you want the loop to repeat as long as a condition exists?
The Do While loop
What is the difference between the Do While loop and the Do Until loop?
The Do While loop iterates until its test expression is false. The Do Until loop iterates until its test expression is true.
Which type of loop is best to use when you know exactly how many times the loop should repeat?
The For loop
If a loop does not have a way of stopping, it is called a ___ loop.
infinite loop
Items property
items that are displayed in a list box or combo box are stored as strings in the Items property
Each repetition of the loop is called a ___
iteration
When this ListBox control's property is set to True, it causes the ListBox control to display its list in multiple columns.
multicolumn
A loop that is inside another loop is called a ___ loop.
nested loop
The ___ method generates a random integer.
next
The ___method generates a random floating-point value.
next double
pseudo-random numbers
numbers that only seem to be random
What buttons automatically appear on an input box?
ok and cancel
iteration
one execution of a loop's conditionally executed statements