Visual Basic Assignment #5
due May 7, 1999

This page has been visited times since April 22, 1999.

What new topics are covered in this assignment?

 

Description of Assignment #5

This assignment will use a Select Case statement to convert a numeric mark to a letter. The following table shows the relationship between the mark and the letter:

Numeric Mark Letter
< 60 F
60 - 69 D
70 - 79 C
80 - 89 B
90 - 99 A
100 A+

Note that there are three different checks that the input must pass before we do the conversion. The first is that there is valid input, i.e. the user did not enter an empty string or click cancel. The second is that the input is in fact a numeric value. The third is that the mark entered is between 0 and 100. It is always good programming to check for all possible data input errors when writing a program. This makes your program more robust and complete.

The method for completing this assignment is as follows.

  1. Put three labels on the form for the titles. Your name should be in the last label instead of mine. Note that the titles are centered on the form.
  2. Add one button to start the program and another to exit the program.
  3. When the user clicks the start button, the following code for the program is run.
  4. Read the mark into a temporary string. If this string is null ("") indicating that the user pressed cancel or did not enter anything, exit the procedure using the "Exit Sub" command.
  5. Otherwise check the string to see if contains a valid number. Use the IsNumeric function to do this.
  6. If the string does not contain a valid number, use a MessageBox to print an error message and exit the procedure.
  7. Otherwise convert the string to a numeric value using the CDbl function, and store it in a variable of type Single.
  8. Test this variable to make sure it is between 0 and 100 inclusively.
  9. If this variable is not between 0 and 100, use a MessageBox to print an error message and exit the procedure.
  10. Otherwise use a Select Case to convert the mark to the corresponding letter. Use Listing 7.5 on page 126 in the textbook to help you do this.
  11. Finally print out the corresponding letter in a MessageBox. This ends the program.

 

There will be no exercise for this assignment, since it is quite straight forward. 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.

Note: Test my program with all the possible input values to see how it works, so that you can make yours the same. When I say all possible input values I mean one value from each mark range, and one value from each possible error category, i.e. no input, non-numeric input, and a mark outside the 0-100 range.

This is how you should test your program as well.

Good luck.

Below are the assignment 5 downloads:

If you have Visual Basic 6 installed on your computer, download the Assignment #5 file only.

If you do not have Visual Basic 6 installed on your computer, you will need the Visual Basic 6 .dll files in addition to the assignment #5 file. The .dll download below is the same one used for assignments 1 to 4, so if you already downloaded it you will not need to download it again. Simply use the same files. Otherwise download both the Assignment #5 file and the Assignment 5 required .dll files below. To run, place all files in the same directory and double-click on calcmark.exe.

Assignment #5 file (4,000 bytes)

Assignment 5 required .dll files (1.3 million bytes)

 

Go back to my main page

Go to Winzip's home page

To e-mail me click here

Page created and maintained by Ron Patterson