CIS 56 INTRODUCTION TO VISUAL BASIC

 

Evening School

Program Assignment #4

Week of March 3,2003

 

This coming Monday, we will be continuing our catching up from where we left off.

I will continue with the shirt program we were looking at in class with a twist.

I will still go over the program with you but I have modified it to incorporate the concepts of procedures and functions. So, the processing we look at will be in procedures and functions instead of all in one event procedure. It will still be the same program. So, dont worry!

This way, we will kill two birds with one stone, so to speak.

 

I will then proceed to introduce the For/Next loop concept and the Nested For/Next Loop. This will include the concepts of Step incrementing and Step decrementing.

 

I will go over Input boxes.

 

I will also look at the list box as a display tool, some of its properties, entering data at design time and run time and, hopefully, the Right$, Left$ and Mid$ functions, as time allows.

 

Next week well look at the Do loops, the combo box, the UCase and LCase functions as well as other functions. If possible I may begin an explanation on arrays.

 

At this point chapters 5 and 7 should be read. You might want to begin Chapter 8. I want us to be well on track before the Spring break.

 

The following assignment may seem somewhat ambiguous at this time but, after Monday night, things should be much clearer.

 

I will be covering many of the concepts in this assignment and will go over the directives with you during the last 15 minutes or so of the class.

 

Those of you who dont come to class are welcomed to ask questions over the WEB.

 

Program assignment directives:

 

For this assignment you are to do the following:

 

You are to put up a form with the following controls.

 

In your code you will have to use input boxes to enter data, procedures and functions to perform routines and calculations respectively and a NESTED FOR/NEXT LOOP. You will also use both modular and local variables.

 

Remember that when you need variables in only one event, procedure or function, and you dont reference them from anywhere else in the form module, you declare them as local. When you need to reference them form various points in the form module code, you declare them to be modular.

 

Scenario/directives:

You enter the number of donors who are contributing to your drive. This will give the end limit of the outer loop

Based on that number, you will enter a donation amount using an INPUT BOX, and run a total of the amount of donations for 6 months at one donation per month. In other words, 6 donation amounts will be entered.

You will then calculate the average of the donations and run a total of all averages calculated for each donor.

You will then ultimately display the average of all donors, the overall average, at the very end of the processing. The 6 donations is the end limit of the inner loop.

 

So, you will use a variable for you outer loops end limit and the number 6 for the inner loops limit.

 

Heres how it should basically run.

 

When cmdNumDonors is pressed, an INPUT BOX should come up prompting the user to enter the number of donors.

 

A PROCEDURE should then be called to verify that a number was entered and not a blank AND that the value entered is, in fact, numeric.

If the value is entered and blank, a message box should come up to tell the user, and the command click event re-called. This is a form of recursion and, Ill quickly explain it Monday.

The same applies to when non-numeric data is entered.

 

Note that the variable taking in the data from the input box must be declared as string. Conversion for numeric values, are to be done afterwards if and as they apply. If this rule is not followed, your cancel on the input box will generate a run time error to the effect of a variable type mismatch. Keep in mind that the area of data entry on an input box is actually a text box and all values entered into a text box are string even if theyre numbers. You all know this now.

 

If a zero is entered, then a PROCEDURE called Quit should be called to end the program run and in that Quit procedure, just before the End command, a message should be displayed to the user that the program is going to end.

In this particular case, you must use END after Unload Me or leave the Unload Me out altogether and just you END. I will quickly explain on Monday as to why this is so.

 

In truth, all data entered should be validated but for this assignment I will require you to only validate the number of donors entered. I will assume that if you can bring about the validation for one entry, you would be able to do it for all entries. This will save you some time. Keep in mind, however, that in future I may, in all likelihood, insist you validate all data.

 

If all is ok with the value entered in the input box, a message should come up to the user that he/she can go ahead and activate the cmdAddDonations.

 

When cmdAddDonations is pressed, a NESTED FOR NEXT loop should then be executed in that command buttons click event.

 

In the outer loop, an INPUT BOX should prompt the user for the donors name.

 

Then, in the inner loop, an INPUT BOX should prompt the user for the donation amount. This prompt should occur 6 times and with each pass through the inner loop, the amount entered should be added to a running total.

 

After the six iterations of the inner loop, a FUNCTION is to be called and the total amount is passed to it, wherein the average is calculated. That average is to be added to a running total of averages to calculate the overall average, just before completion of the run.

 

After the individual average is calculated, another PROCEDURE is to be called wherein the donors name, total donation amount and average donation is to be displayed in the list box.

The individual donation amount for each person should be formatted as number with 2 decimal places to the right of the decimal point.

 

Note the above function and procedure must be done before the Next of the outer loop is executed and after the Next of the inner loop is executed because you are calculating for the current donor. After the Next of the outer loop is executed, you will be dealing with a new donor.

 

Then the next iteration of the outer loop should take place. Hence: we get the next donors name, and another 6 amounts are entered.

 

After all outer looping has been processed, that is, all individual donors have been processed, we get our final, overall average calculated and displayed.

 

In the DispAvgDonations click event, a final FUNCTION is to be called to calculate the overall average and then a last PROCEDURE is to be called that will display the over all average in the list box. Remember youll have to pass the total average amount you have been running to the function.

 

The final average amount should be displayed as format currency.

 

Hint/Reminder: Remember, where applicable clear the previous variables after running totals to avoid logic errors. Remember we spoke of logic errors last week and what they were!!!!!!!!

 

YOU CAN BRING A HARD COPY OF THIS ASSIGNMENT WITH YOU ON MONDAY, IF YOU LIKE, FOR WHEN WE GO OVER IT.

 

REMINDER: YOUR QUIZ IS DUE BY 10:00 P.M. MONDAY MARCH 3RD. PLEASE KEEP THIS IN MIND. NO ACCEPTANCE AFTER THAT TIME.