138 terms

CPT 186 - Visual Basic

All test questions
Syntax error
A project that halts during execution due to a misspelled name of an object or property, was halted due to a(n) _______.
Object oriented programming language
Visual Basic.NET is a(n) _______.
Graphical User Interface
Microsoft Windows uses a GUI environment. GUI (pronounced "gooey") stands for _______.
Design time
While you are creating the user interface you are in _______.
The code that is used in a sub procedure to stop execution of a program is _______.
Logic error
If a project runs, but the results are not correct, this is called a(n) _______.
Change the text in the NameTextBox control to the color red
The code: NameTextBox.ForeColor = Color.Red, will _______.
Text box
You are designing a form and it will be necessary for the user to type in their name. You should use a _____________ for inputting the user's name.
If a radio button is currently selected, its _______ property will be True.
All of the above are objects
Which of the following is not an object?
Set the Visible property to False
If you want to make a PictureBox disappear from the form when the project runs, you must _______.
MessageLabel.Text = MessageLabel.Text & " " & NameTextBox.Text
Which of the following is a valid example of concatenation?
The property used to display information in a TextBox is _______.
Module-level variable
A variable that is declared in the Declarations section of a form is a(n) _______.
What statement should be used to declare a module-level variable?
The format specifier codes
In order to control the number of decimals that will appear when a number is displayed, you can use _______.
What will be the value of AnswerInteger after execution of these statements?
Const NUMBER_A_Integer as Integer = 6
Const NUMBER_B_Integer as Integer = 4
Const NUMBER_C_Integer as Integer = 2
AnswerInteger = NUMBER_A_Integer + NUMBER_B_Integer * NUMBER_C_Integer
Which of the following is not a valid data type?
Which of the following is the correct code that will display the value in TotalSalesDecimal with a percent sign and 2 decimals?
Which of the following has the highest order of precedence in arithmetic expressions?
Remark statements are not executable code.
The Visual Studio IDE will automatically create a new folder for each new project.
After you have added a label to a form you can change the words that are displayed inside the label by changing the Text property.
If the programmer does not write code for a button control, Visual Basic automatically provides code in the Click procedure that will close the form when the user clicks the button.
In Form1.Text, the word Text is referring to a method.
Setting the Cancel property of a button to True will allow the user to press Enter to select the button.
The statement: ItemTextBox.Focus(), will place the insertion point in the text box called ItemTextBox.
Your project requires the user to choose their gender. You should display the choices, Male and Female, using check boxes.
Labels are used primarily for user input.
Joining two strings of text is called concatenation.
The text property of a label or text box control can be cleared by using the Delete method.
If you would like to change the font property of five controls on your form so that they are all the same, you cannot change them as a group, you must change them individually.
A variable that will store totals and that will be available to all procedures in the form must be declared as a constant.
SCHOOL_NAME_String is in the correct format for a constant that holds the name of your school.
A numeric variable that is declared with the Dim statement in a local procedure is initialized to zero each time the procedure occurs.
A variable must be declared with a Dim, Private or Public statement before it is used if Option Strict is turned on.
Data whose value may not be changed during the execution of a project is referred to as a constant.
When using the format specifier codes, you can specify the number of digits to appear to the right of the decimal point.
Message boxes can contain buttons.
AmountTextBox.Text = AmountDecimal.ToString("C")
Write the VB code that will place the contents of the variable AmountDecimal into the text box called AmountTextBox and display the value in a currency format.
Dim ValueDecimal As Decimal
Write the statement to declare a variable called Value that will hold a number that contains a fractional amount. Be sure to add the correct suffix at the end of the variable name.
MessageLabel.Visible = True
Write a statement to make the radio button called BlackRadioButton appear selected.
PrintCheckBox.Checked = False
Write the code to make the check box called PrintCheckBox appear unchecked.
MessageLabel.ForeColor = Color.Red
Write the statement to change the color of the text in label MessageLabel to Red.
PriceDecimal = Decimal.Parse(PriceTextBox.Text)
Catch PriceException As FormatException
MessageLabel.Text("Error in input data.")
End Try
Write the statement(s) to convert the value in the text box, PriceTextBox, to decimal and store the result in the variable PriceDecimal which has already been created (you don't have to write the Dim statement). Add a Try/Catch block so that when an error results during the conversion, display the error message "Error in input data" in the label MessageLabel.
MessageBox.Show("Quantity should be numeric and greater than 0!", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Write the statement(s) to display a Message Box on the screen with the message "Quantity should be numeric and greater than 0!". The Message Box should use "Error" in the title bar and should use the OK button and the Exclamation icon.
Visual Basic is fun
What will display in MessageLabel when the following statements are executed? Assume that CountInteger=10.
MessageString = "Visual Basic is fun"
IF CountInteger <= 10 Then
MessageLabel.Text = MessageString.ToLower
ELSEIF CountInteger > 20 Then
MessageLabel.Text = MessageString.ToUpper
MessageLabel.Text = MessageString
______________ will be the result of: MessageText .Text = MessageText .Text.ToUpper when the value of MessageText .Text is "Visual Basic is fun!".
Which of the following is not a logical operator?
It must begin with Select Case and it must end with End Case
Which of the following statements does not apply to the Case structure?
Both answers b and c are correct
Nested Ifs are allowed, _______.
You can write a set of instructions in an event and then ________ the event from any other procedure.
What is the value of MysteryInteger when the following statements are executed?
Const NUMBER_Integer As Integer = 10
Select Case NUMBER_Integer
Case 1, 3, 5, 7, 9
MysteryInteger = NUMBER_Integer
Case 2, 4, 6, 8, 10
MysteryInteger = NUMBER_Integer + 1 * 2
Case Else
MysteryInteger = NUMBER_Integer * 2 + 1
End Select
Case Else
_______ is an optional clause available for the Case Structure when no match is found in any of the Case statements.
With the logical operator _______ , both conditions must be true for the entire condition to evaluate True.
The Autos Window
You can use _______________ as your project executes in order to view the values of variables and control contents that are referenced in the current statement and a few statements on either side of the current statement.
Which of the following is not a type of common dialog box?
The text property of a menu item can only be changed in the Menu Designer
Which of the following is not true about using keyboard access with a menu item?
EmployeeLabel.Font = FontDialog1.Font
Which of the following is the correct way to assign a font to a label using common dialog boxes after the statement FontDialog1.ShowDialog() has been executed?
You can add a separator between menu items by using the Line control from the toolbox
Which of the following statements about context menus is not true?
It is shown in gray
Which of the following is NOT true about a menu item that has a check mark?
A sub procedure returns a value to the point from which it was called
Which of the following statements is NOT true?
An argument that is passed ByRef cannot alter the original value
Which of the following is NOT true about passing arguments to procedures or functions?
Context menu
If you right-click an object, what type of menu pops-up?
What property in a menu item's property window is used to change the words that will display in the menu?
In an If...Then...Else statement, the Else clause is optional.
The code: If NumAInteger <> NumBInteger Then, evaluates True when NumAInteger=3 and NumBInteger=5.
A block of If...Then...Else must begin with an If statement and end with an EndOfIf statement.
A line of code which is marked as a breakpoint will have a large red dot in the left margin and the code will be highlighted in red.
Or and And are logical operators used in compound conditions.
The Uniform Modeling Language(UML) can be used to nest if statements in code.
It's a good idea to always use the ToUpper or ToLower method on the Text property of text boxes, whenever comparing string values.
The TestChecked CheckBox may be tested to determine if it is checked by using the following code:
If TestChecked.Checked Then
While a program is running, you can stop at a particular location by inserting a breakpoint in the code.
The AND operator requires that both conditions be True for the compound condition to be True.
If you want the user to be able to use the dialog boxes from the Windows environment so they can save files and change colors, you will need to add two common dialog components to your form, the SaveFileDialog for saving files, and the ColorDialog for changing colors.
You can pass arguments to sub procedures and function procedures.
General procedures: sub procedures and function procedures, can be supplied with values, called arguments.
When an argument is sent ByVal, a copy of the argument's value is sent to the procedure so that the procedure cannot alter the original value.
After placing a common dialog control on the form, you can display the dialog box at run time using the OpenDialog method.
It is possible to create procedures that are not associated with click events.
When creating menus with the MenuStrip component, the Name property is used to hold the words that will appear on the screen in the menu bar.
The return value from a function procedure is contained in a variable with the same name as the function.
By default, all new menu items have their Enabled property set to True.
If you click on an item in a menu that is grayed out, you will toggle it on, and it will appear in black text.
DisplayLogoToolStripMenuItem.Enabled = False
Write the code to make the menu selection called DisplayLogoToolStripMenuItem appear grayed out so that it is unavailable.
InputInteger = Integer.Parse(InputTextBox.Text)
MessageBox.Show("Input not numeric")
End Try
Create a set of statements that will validate that the text box object InputTextBox is a numeric value and set the variable InputInteger to the integer value of the InputTextBox object using the Integer.Parse. If the value is not numeric and an exception occurs then display a message box saying "Input not numeric". Use Try/Catch to validate.
If LanguageTextBox.Text.ToLower() = "visual basic" Then
MessageBox.Show("You are programming in Visual Basic!")
End If
Write the statement(s) that will take the value a user has typed into the text box called LanguageTextBox, convert it to lowercase and then test to see if it is equal to the string "visual basic". If the strings match display a message box saying "You are programming in Visual Basic!".
Public Sub ColorToolStripMenuItem_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles _
'Change MessageLabel text color

With ColorDialog1
.Color = MessageLabel.ForeColor
MessageLabel.ForeColor = .Color
End With

End Sub
Write the code for the ColorToolStripMenuItem menu selection that will allow the user to change the color of the MessageLabel text to the color selected by the user from the ColorDialog1 Color dialog box when the menu selection is clicked. Below you will be given the first and last lines of the procedure and you are to write the rest.

Public Sub ColorToolStripMenuItem_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles_
'Change MessageLabel text color

'Your code goes here

End Sub
Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click

With FontDialog1
.Font = NameTextBox.Font
NameTextBox.Font = .Font
End With
End Sub
Write the code for the FontToolStripMenuItem menu selection that will allow the user to change the font properties of the NameTextBox text to the font properties selected by the user from the FontDialog1 Font dialog box when the menu selection is clicked. Below you will be given the first and last lines of the procedure and you are to write the rest. Be sure to include the Private Sub event header and the End Sub at the end.
If you need to have a form disappear and you want it removed from memory you should use the _______ method.
Add Existing Item
To add a form from another project into your project, select _______ from the "Project" menu.
Startup form
When a project begins the first form to display after the Splash Screen if there is one is called the _______.
Close method
If you have many forms in your project and you are sure you won't need a form again, it is best to use the _______ when making the form disappear.
Variables declared as _______ are available only to the one form.
Both answers A and C would remove a form from a project.
You can remove a form from a project by _______.
How many times will the statements inside this For/Next loop be executed?
For IndexInteger = 2 to 12 Step 3
'Statements in loop
Next IndexInteger
will make the program difficult to read and understand
Incorrect indentation of the statements in For/Next loops _______.
setting the Sorted property to True
Items in a list can be placed in alphabetical order by _______.
ColorListBox.Items.RemoveAt (ColorListBox.SelectedIndex)
The code to delete the selected item from ColorListBox is _______.
hold a list of values
List boxes and combo boxes _______.
Answers A and B are correct
The data that appears in a combo box when it is first displayed can be added to the combo box _______.
TextChanged event
Which text box event occurs each time the user types a character into a text box?
the user should be notified if there is no match found in the table
When performing a table lookup, it is a good idea to include validation because _______.
an element
An array is a set of variables. Each individual variable is called _______.
For Each / Next statement
When you are working with an array, the easiest way to traverse the elements without using a subscript is to use the _______.
TotalSalesDecimal(1) += SalesDecimal
Which of the following code samples is valid for accumulating the total sales for the Tigers baseball club if the Tigers are the second group in the list?
What is the value of NameString(1,1) after the following declaration is initialized?
Dim NameString ( , ) As String = {{ "James", "Mary"},{ "Sammie", "Sean"}}
A table lookup
__________ can be used to find a specific value in an array.
How many elements are contained in the array created with the following code?
Dim EmployeeString(25) As String
In order to make a splash screen appear when a project begins, you must designate the form that is the splash screen in the Project Designer.
About boxes are typically displayed by selecting "About" from the "Help" menu.
The form's Load event occurs each time the form is displayed.
Add a new form to a project by selecting "Add Windows Form" from the "Project" menu.
Using a static local variable is better than using a module-level variable because it is always best to keep the scope of a variable as narrow as possible.
If a variable is declared with a Dim statement in a sub procedure, all other forms in the project will have access to that variable.
The programmer can change the program's version by modifying the Assembly Information.
If you want to remove an item from a list during run time, you can use either the Items.RemoveAt method or the Items.Remove method.
The counter in a For/Next loop can be a variable or a constant.
The Continue statement can be used to skip to the next iteration of a loop.
List boxes have a Text property but it can only be accessed at run time.
The code, "NameLabel.Text = NameComboBox.Text", or the code, "NameLabel.Text = NameComboBox.Items(NameComboBox.SelectedIndex)" will display the selected name in NameLabel.
Boolean variables are commonly referred to as switches or flags.
The SelectedIndex property can be used to select an item in the list or to determine which item is selected.
When an array is initialized with the Dim Statement, the index starts at 1 instead of 0.
An array is a list or series of values.
The following code is valid for declaring an array with ten elements: Dim employeeNameString(0 to 10).
An exception is automatically thrown if a subscript is used that is not a valid element in an array.
A table lookup is used to find a match for a specific value (or string) by comparing it to each element in an array.
The SelectedIndex property of a list box can be used as an array subscript to find an item in a list box.
Write the statement(s) to make the entry in the text box called MajorTextBox appear selected when the text box's Enter event procedure occurs. The first and last lines of the procedure are given. You just need to write the single statement that will be placed inside the procedure.
Write a statement to close the form called ShirtsForm.
Write the statement to make the form named, MainForm,
disappear and be removed from memory.
Dim AmountDecimal(14) As Decimal
Write a statement to create a one-dimensional decimal array called
AmountDecimal that will contain 15 elements.
MessageBox.Show("The number of flavors in the list is " & FlavorsComboBox.Items.Count)
Write the statement to display the message "The number of flavors in the list is " followed by the number of items in the combo box called FlavorsComboBox in a message box.
For CountInteger = 50 to 0 Step ‐5
'statements in loop
Next CountInteger
Write the first and last lines of a For/Next that will start
the value of the LoopIndex variable called
CountInteger at 50 and will count down by 5's until
the value in CountInteger is less than 0.
For RowInteger as Integer = 0 to 5
For ColInteger as Integer = 0 to 5
AmountDecimal(RowInteger, ColInteger) = 0.0D
Next ColInteger
Next RowInteger
Given the declaration for the following 2 dimensional array, write the statements to initialize the elements of the AmountDecimal array to 0.0D. Assume that the array has already been loaded with decimal values and your code will be used to reinitialize the array back to 0. Include the Dim statements for any additional variables that you might need.
For IndexInteger = 0 to 5
CountInteger(IndexInteger) += 5
Next IndexInteger
Given the following variable declarations, write a For/Next loop to add 5 to each element of the CountInteger array. Assume that the array has already been loaded with integer values and your code will increment each array element by 5.