4. Practicals

Programming labs in Visual Basic. Each builds a skill you need for Assignment 2.

Before you start

  1. Your first Windows Forms program
  2. Two-number calculator
  3. Temperature converter (from design to code)
  4. Selection: login and grade calculator
  5. Loops: tables, totals and guessing game
  6. Arrays and strings: team list
  7. File handling: save and load a list
  8. Make it robust: validation and error handling
  9. Debugging challenge
  10. Mini project: quiz program

Practical 1: Your first Windows Forms program

45 minLesson C1
  1. Install or open Visual Studio Community. Create a new project: Windows Forms App (.NET Framework), language Visual Basic, name HelloApp.
  2. From the Toolbox add a TextBox (txtName), a Button (btnHello, Text “Say hello”) and a Label (lblMessage).
  3. Double-click the button and type: lblMessage.Text = "Hello, " & txtName.Text
  4. Press F5 to run. Type a name and click the button.
  5. Change at least three properties (form BackColor, label Font and ForeColor, button Text) and run again.
Check it works: The label greets the name you type.
Keep: A screenshot of your form running, and of the Properties you changed.

Practical 2: Two-number calculator

60 minLesson C2
  1. Make a form with two text boxes, four buttons (+, −, ×, ÷) and a result label.
  2. Declare variables with suitable data types and write code for each button.
  3. Move the calculation into a function so each button calls it.
  4. Add an extra button that shows the remainder using Mod.
  5. What happens if you divide by zero, or type a letter? Note it down: you will fix it in Practical 8.
Check it works: All four operations give correct answers.
Keep: Annotated code (comments on every part) and screenshots.

Practical 3: Temperature converter (from design to code)

45 minLesson B4
  1. Write pseudocode for a program that reads °C, converts it to °F with F = C × 9 / 5 + 32, and displays the result.
  2. Draw the flowchart and dry-run it with a trace table for 0, 37 and 100.
  3. Build it in Visual Basic, using a constant where sensible.
  4. Compare your program with your design. Did you need to change anything?
Check it works: 0 → 32, 37 → 98.6, 100 → 212.
Keep: Pseudocode, flowchart, trace table and the program.

Practical 4: Selection: login and grade calculator

60 minLesson C3
  1. Make a login form: a password box (set PasswordChar to *) and a button. Show “Access granted” or “Access denied”.
  2. Make a grade calculator for a mark out of 100 using If … ElseIf … Else.
  3. Make a Select Case program that turns a day number 1–7 into the day name, with Case Else for anything else.
  4. Write a test table for the grade calculator with normal, boundary and erroneous data.
Check it works: Every boundary mark gives the correct grade.
Keep: Code and your test table.

Practical 5: Loops: tables, totals and guessing game

60 minLesson C4
  1. Use a For loop to show any times table (chosen by the user) in a ListBox.
  2. Show the running total of 1 to N in a multiline text box.
  3. Build a guessing game: the computer picks a number 1–50 (Dim r As New Random : secret = r.Next(1, 51)); use a loop to give “higher/lower” hints until the user guesses it, then show the number of guesses.
  4. Explain which loop you used for each part and why.
Check it works: The game always ends when the right number is guessed.
Keep: Code and screenshots.

Practical 6: Arrays and strings: team list

60 minLesson C6
  1. Use InputBox in a loop to store six player names in an array, then display them in a ListBox.
  2. Add a Search button that finds a name and shows its position, or “not found”.
  3. Show each player’s initials in capitals using Substring and ToUpper.
  4. Sort the names alphabetically with Array.Sort and show them again.
Check it works: Searching for a name that is not in the list shows “not found”.
Keep: Code and screenshots.

Practical 7: File handling: save and load a list

60 minLesson C7
  1. Add a Save button to Practical 6 that writes every name to team.txt (one per line) using StreamWriter.
  2. Add a Load button that reads the file back into the ListBox using StreamReader.
  3. Close the program, open it again and load the names. They should still be there.
  4. Make it robust: if the file does not exist, show a friendly message instead of crashing.
Check it works: Names survive closing and reopening the program.
Keep: Code, the text file contents and screenshots.

Practical 8: Make it robust: validation and error handling

45 minLesson C7
  1. Go back to your calculator (Practical 2).
  2. Add a presence check and a type check (Integer.TryParse or Decimal.TryParse) to every input.
  3. Stop division by zero with a helpful message.
  4. Wrap risky code in Try … Catch and show a friendly error.
  5. Re-run your tests from Practical 2. What changed?
Check it works: No input you can type will crash the program.
Keep: Before-and-after test results.

Practical 9: Debugging challenge

45 minLesson C8
  1. Your teacher gives you a program with three faults (one syntax, one runtime, one logic).
  2. Use the Error List to find the syntax error.
  3. Use test data to make the runtime error happen, then fix it with validation.
  4. Set a breakpoint (F9), step through (F10) and watch the variables to find the logic error.
  5. Record each fault in a table: type, symptom, cause, fix, re-test result.
Check it works: All three faults are fixed and re-tested.
Keep: Your fault table.

Practical 10: Mini project: quiz program

Two lessonsLesson B3
  1. Design a quiz program: a question, four answers labelled A–D, a Submit button, a Quit button and an area that shows whether the answer was right (as in your scheme of work).
  2. Produce two alternative screen layouts and a navigation diagram, and choose one with a reason.
  3. Store at least five questions in arrays (or an array of records), with the correct answers.
  4. Develop it with selection, a loop or counter for the score, and comments throughout.
  5. Test it, get feedback from two classmates, improve it, and write a short review. This is practice for your assignments; do not reuse it as assignment evidence.
Check it works: The final score is correct for any set of answers.
Keep: Design, code, tests, feedback and review: your practice portfolio.