General
Purpose Packages
Automated
Systems
Commercial Data
Processing
Computer Systems
Hardware
Computer Systems
Software
Programming Course
Arrangements

Loops in the Top Level (or Main Program)

Variable Loops & Input Boxes

 

Much to consider here!

  1. If you can keep loops out of subroutines, and code them in the top level of a program it saves you having to think about the loops when writing the code for the subroutines.
  2. Not all loops go from 1 to 10 or 1 to 100 etc. Here, we consider how the user can choose how many times a loop repeats.
  3. Text boxes have been used so far to take in user input. However, every time a text box is required, the busier a form gets. How can we stop having to many text boxes on a form? Time to meet input boxes.
  4. But before then, lets have a look at how loops can be included in the top level of the program

 

Play this video
Putting a Loop in the Main Program! Go Full Screen to see in greater detail?

1. Loops at the Top Level

  1. Watch Movie 17 which shows how Input Boxes can be used and how the user can control how many times a loop is repeated.
  2. Click the button to download the Exam Results program. Make sure you choose Save
  3. Move the program to your VB Program folder. Right click on the zipped folder and choose Extract All or Extract Files. Click OK or Next and keep going until the process is Finished..
  4. Create the code for the top level of the program only.
download Exam Results

 

 

Play this video
Coding for Input Boxes!Go Full Screen to see in greater detail?

2. Coding for Input Boxes

  1. Watch Movie 18 which shows the code for the Input Boxes.
  2. Complete the code for the Exam Results program and test fully that the program works as expected. .

 

 

 

 

 

 

 

 

Play this video
Controlling the Loop! Go Full Screen to see in greater detail?

3. Using Variable to Control the Loop

Here we see how the loop counter can be used for more than just counting how many times a loop has been performed.

It's a variable and acts like any other variable and in this program the value of the counter will be displayed as part of the output in the program.

 

  1. Watch Movie 19 which shows how a control variable can be used and displayed in a program.
  2. Click the button to download the program folder Times Tables. Make sure you choose Save
  3. Move the folder into your VB Programs folder in Documents. Right click and choose Extract All or Extract Files. Click OK or Next and keep going until the process is Finished..
  4. Create the code for the program and check it works for various tables going from 1 to 12.
  5. Change the program to allow the user to decide what value the chosen table goes up to instead of always being 12.
Download Times Tables

 

 

 

 

What you have to do!

  1. Watch Movie 17 and create the code for a LOOP in the Top Level of the Exam Results program.
  2. Watch Movie 18 and in the Exam Results program write the code for the Input Boxes.
  3. Watch Movie 19 and add in the code for the control variable in the Times Table program

 

Mark off Exercise 13 in your progress grids.

 

What you MAY have to do!

Ask your teacher whether you should do the following task.

 

Assessment 4 (A4). Complete the assessment CAR HIRE in your progress grids

 

 

What you should now be able to do!

 

Continue to Exercise 14: More Loops & Message Boxes

 


 

 

 

 

Home | S1 Topics | S2 Topics
Computing Standard Grade | Info Systems Intermediate II | Info Systems Higher | Internet Safety
Log into Glow | School Website | Contact Us