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

The Do Loop and Validation

 

Why use computers?

Because computers cut down mistakes happening.

  1. Data validation can be introduced to Visual Basic Express programs to make sure that only sensible data is input in a program.
  2. Data validation should be used in all programs involving input and a key aspect in this involves the use of a new kind of loop - the Do Loop Until.

 

1. Introducing DO LOOP UNTIL.

Play this video
Code for DO LOOP UNTIL! Go Full Screen to see in greater detail?
  1. Watch Movie 23 which shows you how to validate data entered or input by the user.
  2. Click the button to download the program Average2 folder. Make sure you choose Save
  3. Move the folder into your VB Programs folder
  4. Right click on the folder and choose Extract All or Extract Files. Click OK or Next and keep going until the process is Finished..
  5. Add in the code for the Do loop and the If statement with the message box.
  6. Test that the program works for a variety of different input values, both valid and invalid.

 

download Exam Results

 There might be a problem - See your teacher to get this program.

 

 

In future, any program you write involving input should have similar validation checks applied!

 

2. Introducing Random Numbers

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

Very often computer programs have to generate random numbers for a variety of reasons.

Let's see how random numbers are created, and then used in a program requiring a Do loop.

 

  1. Watch Movie 24 which introduces functions and the code required to produce random numbers.

 

 

 

 

 

3. Using the Random Number Function

Play this video
Controlling the Loop! Go Full Screen to see in greater detail?
  1. Watch Movie 25 which shows you how the random number function can be included within the Darts program.
  2. Click on the button to download the 16Dart program folder. Make sure you choose Save.
  3. Move it to your VB Programs folder.
  4. Right click on the zip file and choose Extract All or Extract Files. Click OK or Next and keep going until the process is Finished..
  5. Write the code for the program and test fully that it works. Do not try to write the code for the Reset button just yet.
  6. Tick Off your Progress Grids.
Download Times Tables

 

 

 

 

4. Resetting Variables and Clearing a ListBox

Good practice means that when a button is used to run a program more than once, then the variables used in the program should have their values set to 0 (for numeric variables - string variables should be set to contain no value).

Continually pressing a button to re-run a program can involve the listbox used to display output becoming very full.

See if you can work out how to "Clear" Listboxes and tie this to a Clear or Reset Button.

 

 

What you MAY have to do!

Ask your teacher whether you should do the following task.

 

Assessment 5 (A5). Complete the assessment GUESS NUMBER in your progress grids

 

What you have to do!

  1. Watch Movie 23 to see how to add the code for the DO LOOP UNTIL to check that the numbers entered into the program are Vaalid.
  2. Watch Movie 24 to see an introduction to the Random Number function..
  3. Watch Movie 25 to see how the Random Number function applied in a program. Download and use the code in the 16Dart program.
  4. Discover the single line code used to reset Listboxes.

 

Mark off Exercise 16 in your progress grids.

 

What you should now be able to do!

 

Continue to Exercise 17: Useful Functions

 


 

 

 

 

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