Visual Basic
Assignment #7
This page has been visited
times since May 10, 1999.
What new topics are covered in this assignment?
About Loops
Loops execute the same code over and over until a certain condition is met. In the case of the Do Loop Until loop, the code between the Do and the Loop Until statements is executed repetitively until the condition after the Until statement is met. In the case of the Do Loop While loop, the code between the Do and the Loop While statements will be executed as long as the condition after the While statement is true.
For example. In the code below the numbers 1 to 10 are printed in a label. This is because the code between the Do and Loop Until instructions are done repetitively until x is greater than 10. Notice that I add 1 to the value of x each time the loop is executed. This makes sure that the loop will eventually end and I will not have an infinite loop.
x = 1
Do
label1.caption = label1.caption + cstr(x) + chr(13)
x = x + 1
Loop Until x > 10
This is the same code using the Do Loop While statement
x = 1
Do
label1.caption = label1.caption + cstr(x) + chr(13)
x = x + 1
Loop While x < 11
Description of Assignment #7
In this assignment you will use both the Do Loop Until statement and the Do Loop While statement.
In the first part of the assignment you will use the Do Loop While statement to create a Celsius to Fahrenheit conversion table for Celsius values from -30 to + 30 in increments of 5. You should create a loop that changes the value of Celsius from -30 to +30 in increments of 5, and then calculate the Fahrenheit value from it. Use CStr to print out the values in the labels. Use the code above to help you create the loop. [F = C * 9 / 5 + 32]
Hint: Use one label for the Celsius and one for the Fahrenheit when printing the table. It will make it easier to line them up.
In the second part of the assignment you will
use the Do Loop Until statement to continually read
a user's input until the user indicates that he/she wants to
stop. This is done in the following manner.
Take a look at my executable to see how mine works. Try to make yours work identically.
As always, you should read the pertinent parts of the textbook before doing the assignment. If you have any questions please email me. The executable of this assignment can be downloaded below.
Good luck.
Below are the assignment 7 downloads:
If you have Visual Basic 6 installed on your computer, download the Assignment #7 file only.
If you do not have Visual Basic 6 installed on your computer, you will need the Visual Basic 7 .dll files in addition to the assignment #7 file. The .dll download below is the same one used for assignments 1 to 6, so if you already downloaded it you will not need to download it again. Simply use the same files. Otherwise download both the Assignment #7 file and the Assignment 7 required .dll files below. To run, place all files in the same directory and double-click on loops.exe.
Assignment #7 file (5,000 bytes)
Assignment 7 required .dll files (1.3 million bytes)
To e-mail me click here
Page created and maintained by Ron Patterson