Study guide: Visual Basic Event Coding

Course Outline

  1. Object Background and Text Colors
  2. PictureBox Images and Sizing
  3. Visible and Enabled Properties
  4. Running a Visual Basic Program
  5. Event Handlers and Visual Basic Syntax
  6. Statements and IntelliSense
  7. Comments and Error Correction
  8. Procedures and Program Output
  9. Event Planning and Coding Phase

1. Object Background and Text Colors

Key Concepts & Definitions

  • BackColor: the color displayed in its background
  • ForeColor: the color displayed in its text

Essential Points

  • 🔄 To set the form's background color to white:
    1. Select the Windows Form.
    2. Display the BackColor property in the Properties window and open its color list.
    3. Select the Web tab.
    4. Choose White.

Memory Hook

BackColor colors the background; ForeColor colors the text.

2. PictureBox Images and Sizing

Key Concepts & Definitions

  • PictureBox: used to display a graphic image

★ Must-know

  • 🔄 To display an image in a PictureBox:
    1. Locate the image on the web, computer, or local school network.
    2. If it is on the web, save it to a folder on the computer.
    3. Import it into the program's Resources folder.
    4. Specify the image for the PictureBox.

Further detail

  • To import an image, select the PictureBox, open its Image property and resource selector, choose Import, locate and select the file, and confirm with Open and OK.

  • 🔄 To stretch an image to the PictureBox:

    1. Select the PictureBox.
    2. Display the SizeMode property in the Properties window.
    3. Open the SizeMode list.
    4. Choose StretchImage.
  • Multiple images can be placed in the program's Resources folder.

Memory Hook

Locate, import, display, then size the image.

3. Visible and Enabled Properties

★ Must-know

  • Setting a PictureBox object's Visible property to False hides the object.
  • Setting an object's Enabled property to False disables the object.

Further detail

  • 🔄 To hide a PictureBox in the Properties window:

    1. Select the PictureBox.
    2. Display the Visible property.
    3. Open its value list.
    4. Choose False.
  • 🔄 To disable an object in the Properties window:

    1. Select the object.
    2. Display the Enabled property.
    3. Open its value list.
    4. Choose False.

Memory Hook

Visible controls display; Enabled controls whether an object is enabled.

4. Running a Visual Basic Program

Key Concepts & Definitions

  • Running a Program: compiles, or translates, Visual Basic instructions into instructions the computer can execute

Essential Points

  • To run a program in Visual Studio 2017, point to and then select the Start Debugging button on the Standard toolbar.

5. Event Handlers and Visual Basic Syntax

Key Concepts & Definitions

  • Event handler: Responds to an event triggered by a user action by executing code that performs the required processing.

Essential Points

  • 🔄 Create a button event handler by following these steps:
    1. Open the desired program with the Design tab visible.
    2. Point to the desired button object in the Windows Form.
    3. Double-click or double-tap the button object.

6. Statements and IntelliSense

Key Concepts & Definitions

  • IntelliSense: Displays allowable entries for a Visual Basic statement when a period, equal sign, or another special character is required.

★ Must-know

  • Visual Basic syntax specifies how each statement must be written.

Further detail

  • To enter a statement with IntelliSense, type the object name, continue entering letters until the desired entry is selected, press the key for the next character, and repeat the selection process for the desired property or value.

  • When a user taps or clicks a button while a program is running, the action associated with the corresponding coding statement occurs.

7. Comments and Error Correction

Key Concepts & Definitions

  • Build error message: Means that the Visual Basic compiler detected a coding error in the program.

★ Must-know

  • A Visual Basic comment begins with an apostrophe.

Further detail

  • 🔄 Insert comments after generated event code by following these steps:

    1. Place the insertion point at the end of the line beginning with Private.
    2. Press ENTER to create a blank line.
    3. Type the comment line beginning with an apostrophe.
    4. Press ENTER again.
  • 🔄 Add an introductory program-name comment by following these steps:

    1. Place the insertion point before Public on the first line.
    2. Press ENTER and then UP ARROW.
    3. Type an apostrophe, a space, and Program Name:, then press TAB.
    4. Type the program name and press ENTER.
  • 🔄 Correct the illustrated missing-apostrophe error by following these steps:

    1. Choose No in the build-error dialog.
    2. Double-click the error line.
    3. Place the insertion point in the far-left column of that line.
    4. Type an apostrophe.
  • Using IntelliSense considerably reduces the likelihood of coding errors, and forgetting an apostrophe in a comment is one possible error.

Memory Hook

A missing apostrophe turns comment text into code and triggers a build error

8. Procedures and Program Output

Key Concepts & Definitions

  • Procedure: A set of prewritten code that a statement in a Visual Basic program can call for processing.
  • Close procedure: Closes a window and terminates a program.

Essential Points

  • 🔄 Enter the Close statement by following these steps:

    1. Place the insertion point where the statement should appear.
    2. Type clo to highlight Close in IntelliSense.
    3. Press ENTER.
  • Left and right parentheses immediately following a procedure name identify a Visual Basic statement as a procedure call statement.

9. Event Planning and Coding Phase

Key Concepts & Definitions

  • Event: Occurs when a user initiates an action that causes a program to perform appropriate processing in response.
  • Event-planning document: A table specifying the user-interface objects that cause events, the user actions that trigger them, and the processing required for each event.

★ Must-know

  • Phase 4, Code the Program, begins after events and their tasks have been identified and consists of entering Visual Basic statements to accomplish the tasks specified in the event-planning document.

Further detail

  • During Phase 4, the developer enters the code and implements the program logic.

Test yourself

Take a 11-question practice quiz on Visual Basic Event Coding, with every answer explained.

1. A button has a blue background and black lettering. Which property controls the blue area behind the lettering?

2. A developer wants a Windows Form's background to be white. Which sequence uses the form's color picker as described?

Take the quiz →

Study with flashcards

Memorize the key concepts of Visual Basic Event Coding with 10 flashcards.

What color does an object's BackColor display?

Its background color.

What color does an object's ForeColor display?

Its text color.

What is a PictureBox object used to display?

A graphic image.

See the flashcards →

Related classes

Make your own study guides

Upload your class notes and Revizly writes a study guide, a quiz and flashcards in about a minute.

Study guide maker