Here are the answers to all the questions from the second document:
QUESTION ONE (30 MARKS)
(a) Define Visual Basic programming language (2 Marks)
Visual Basic is an event-driven programming language developed by Microsoft for creating graphical
user interface (GUI) applications easily and efficiently.
(b) Explain the main difference between object-oriented and procedural programming languages (2
Marks)
Object-Oriented: Based on objects and classes. Encourages reusability and encapsulation.
Example: Visual Basic.
Procedural: Based on procedures and functions. Focuses on the sequence of operations.
Example: Pascal.
(c) Describe the two elements of a Visual Basic application. (2 Marks)
1. User Interface (UI): The visual components (forms, buttons, labels) seen by users.
2. Code (Logic): The instructions or logic controlling the application's behavior.
(d) Explain the difference between the Dim and Global variable declaration (3 Marks)
Dim: Declares variables with local scope (visible within the procedure or module).
Example: Dim x As Integer = 10
Global: Declares variables accessible across all modules and forms.
Example: Global counter As Integer = 0
(e) Giving examples, explain the difference between methods and properties (4 Marks)
Method: An action an object can perform, e.g., TextBox.Clear().
Property: An attribute of an object, e.g., TextBox.Text = "Hello".
(f) Describe the available commands for a message box (4 Marks)
1. Show: Displays a message box.
Example: MessageBox.Show("Hello")
2. Buttons: Includes OK, Cancel, Yes, No.
Example: MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo).
3. Icons: Display warning or info icons.
Example: MessageBox.Show("Error!", "Alert", MessageBoxIcon.Error).
(g) Define a VB statement and explain two types of conditional statements (3 Marks)
VB Statement: A single line of code executing an action.
Conditional Statements:
1. If...Then: Executes code if a condition is true.
Example:
2. If age > 18 Then MsgBox("Adult")
3. Select Case: Handles multiple conditions.
Example:
4. Select Case grade
5. Case "A": MsgBox("Excellent")
6. End Select
(h) Describe the difference between design-time and run-time in Visual Basic. (4 Marks)
Design-Time: When you design the application interface and write code.
Run-Time: When the application executes and users interact with it.
(i) Describe any SIX elements displayed in the IDE by default. (6 Marks)
1. Toolbox: Provides controls for designing the UI.
2. Solution Explorer: Displays project files and structure.
3. Properties Window: Shows properties of selected controls.
4. Form Designer: Allows designing the application's UI.
5. Code Editor: For writing and editing code.
6. Output Window: Displays logs or debug messages.
QUESTION TWO (20 MARKS)
(a) Reasons for implementing VB over procedural languages like Pascal (4 Marks)
1. Easier to develop GUI applications.
2. Supports event-driven programming.
3. Encourages modularity with objects.
4. Built-in debugging tools for faster development.
(b) Steps involved in creating a VB application (4 Marks)
1. Design the UI: Add controls like buttons, labels, and text boxes.
2. Write code: Add event-driven logic behind controls.
3. Test: Run and debug the application.
4. Compile and Deploy: Package the application for users.
(c) Difference between the Name and Text properties (5 Marks)
Name: Internal identifier for a control in code.
Text: The visible caption or value displayed on the control.
(d) Fundamental Object Types and Their Uses (7 Marks)
1. Label: Displays static text.
2. TextBox: Accepts user input.
3. Button: Triggers actions when clicked.
4. CheckBox: Allows multiple selections.
5. RadioButton: Allows single selection in a group.
6. ListBox: Displays a list of items.
7. ComboBox: A drop-down list allowing selection or input.
QUESTION THREE (20 MARKS)
(a) Three events for the form object (3 Marks)
1. Load: Triggered when the form loads.
2. Click: Triggered when the form is clicked.
3. Close: Triggered when the form is closed.
(b) Available icons for a message box (4 Marks)
1. Error: Displays an error icon.
2. Information: Displays an info icon.
3. Warning: Displays a warning icon.
4. Question: Displays a question icon.
(c) Program to add and subtract integers (6 Marks)
Dim num1 As Integer = 10
Dim num2 As Integer = 5
MsgBox("Sum: " & (num1 + num2))
MsgBox("Difference: " & (num1 - num2))
(d) Why does TextBox have no caption? (2 Marks)
The TextBox displays user input or text directly, so it doesn’t need a caption like a Label.
(e) Program to copy text between TextBoxes (5 Marks)
txtBox2.Text = txtBox1.Text
txtBox2.Font = New Font(txtBox2.Font.Name, 28)
QUESTION FOUR (20 MARKS)
(a) Four basic parts of a VB program (4 Marks)
1. Declarations: Variable and constant declarations.
2. Input: Accept user data.
3. Processing: Perform logic and calculations.
4. Output: Display results.
(b) Code to clear a TextBox (5 Marks)
TextBox1.Clear()
(c) Four structures of the If statement (4 Marks)
1. Simple If:
2. If x > 10 Then MsgBox("Yes")
3. If...Else:
4. If x > 10 Then MsgBox("Yes") Else MsgBox("No")
5. Nested If:
6. If x > 10 Then
7. If y > 5 Then MsgBox("Yes")
8. End If
9. If...ElseIf:
10. If x = 1 Then
11. MsgBox("One")
12. ElseIf x = 2 Then
13. MsgBox("Two")
14. End If
(d) Program to display "Pass" if marks > 50 (5 Marks)
If marks > 50 Then
Label1.Font = New Font(Label1.Font.Name, 18)
Label1.Text = "Pass"
End If
QUESTION FIVE (20 MARKS)
(a) Six data types in VB (6 Marks)
1. Integer: Whole numbers.
2. Double: Decimal numbers.
3. String: Text.
4. Boolean: True/False values.
5. Date: Dates and times.
6. Char: Single character.
(b) General form of counter loop (3 Marks)
For i = 1 To 10
MsgBox("Hello")
Next
(c) Program to print "Hello" five times (5 Marks)
For i = 1 To 5
MsgBox("Hello")
Next
(d) Meaning of constructs (6 Marks)
1. Sequential Constructs: Executes instructions in order.
2. Selection Constructs: Executes based on conditions (e.g., If...Then).
3. Iterative Constructs: Repeats code (e.g., loops).
Let me know if you need clarification!