CIS 56 INTRODUCTION TO VISUAL BASIC

 

Evening School

Programming Assignment 5

Week of March 17,2003

 

First Programming Assignment on Arrays:

 

SCENARIO:

 

This assignment will be the first of two parts and possibly three.

 

Some of the things I will be asking you to do; you might not understand until after our class Monday night. Then, things should be much clearer.

 

It will allow you use several things/features weve looked at so far and/or youve read about so far.

This is a non-realistic library return program where members return hard covered books, soft covered books, Videos, DVD, or Cassettes.

 

You are to design a form.

 

You are to mount the following controls on the form.

 

 

THE CONTROL PROPERTIES:

 

The form:

Name the form frmArrayOne

Set the property to have it centered when run

Set the property to keep the form from being moved around

Set the property to keep it from being resized.

o       Keep in mind to make sure your form is not larger than needed nor too small for whats needed.

Give the form a Caption

 

The text box for the member ID:

Name it txtMemId

Set the property necessary, to insure its length is 5 characters long.

Set the TabIndex to 0

The text box for the member name:

Name it txtMemName

Set the length to be no longer than 25 characters

Set the TabIndex to 1

The text box for the items id:

Name the text box txtItemId

Set the length to be 8 characters in length

Set the TabIndex to 2

The text box for the items title:

Name the text box txtItemTitle

Set the length to be 30 characters in length

Set the TabIndex to 3

 

The label for the current date:

Name it lblCurDate

Set the autosize

Set the Caption to null

The frame:

Name it fraItemType

Set the caption to Select Item Type

 

The option button array:

Name the first button optItem

(Remember one name is all you use for a control array)

Beginning with the first option button, give each a caption as follows:

Hard Cover .25

Soft Cover .15

Video .75

DVD 1.10

Cassette .80

 

 

The text box for the quantity of items:

Name this text box txtItemQty

Set the alignment to right justify

Set the tabstop to false

 

The text box for the number of days late:

Name this text box txtDaysOver

Set the alignment to right justify

Set the tabstop to false

 

These text boxes should be placed on the form to the right of the frame

 

The list box, labels for display, picture box etc.

Whatever method of display you use, you may name it whatever you want.

 

In the code you will be using:

Two single dimensioned variable arrays

For next loops

If statements

Procedures

At least one function

Modular and local variables

The select case statements

Message boxes with vbokonly

Message box(es) with vbyesno

Messsage box with vbokCancel

 

Program Specifications:

 

You will dimension two variable arrays of the same length as the number of returnable items.

In other words each array will have 5 elements.

 

The first array you will name QuantityArray.

The second you will name AmountArray

 

Dim these in general declarations

 

How the program should run:

 

When you start the program, you enter a member id.

The id has to be 5 characters in length but does not have to be numeric

For this entry, you will put code in this text boxes VALIDATE event. I will explain this event in class tomorrow.

In the event you will test that there is something entered in the id text box and that it is 5 characters long and no less.

The validate event is fired off when you tab from the text box to the next text box.

Your message boxes will use VbYesNo buttons and you will use the Select Case to test the results of the message box response.

When the id has to be re-entered you will use the With / End With to code the setfocus, selstart and the sellength. You will also be using the Len function in this feature.

 

For the test to see if nothing was entered and the test to insure the id length was 5 characters long, the message box vbyes response will allow the user to fix the problem. The VbNo will call a procedure to end the program run.

 

Again I will explain all this tomorrow with a similar program.

 

You will then enter the members name and in that text boxes validate event you will check to be sure the text box is not blank.

 

When you enter the item id, you will do the same checking in the validate event of the item id text box, as you did for the member id but the length must be 8 characters in length.

 

Then you will enter the items title and do the same checking you did for the members name in the item titles text box validate event.

 

In the validate event for the item title you will include, at the end, a message box telling the user all the data so far is ok and to select one of the option buttons for an item.

 

You then click an item s option button.

Remember that a control array has only one series of events to which all the controls in the array are subordinate, so, theres only one click event to which all the option buttons work from.

 

In that click event, you will use the index as your subscript.

Note that the variable Index is already in the parameter line of the click event and it is declared as integer by default. Subscripts are integer values.

 

Using the select case statement and the index as the argument, you will assign the penalty value associated with the item modified by the index, to a respective modular variable you have declared.

 

After the Select Case statement you will set the focus to the text box to enter the quantity being returned.

This will allow you enter a quantity number.

 

You will utilize the quantity text boxes LOST FOCUS event to test that data was entered and that it is numeric. There are times when the Lost focus event can be used instead of the actual validate event. If not you will use a message box and reset accordingly and you will exit sub.

 

If all checks out, you will assign the quantity entered to a respective modular variable and then set the focus to the number of days text box.

 

In the number of days text boxes LOST FOCUS event you will test just as you did for the quantity.

If all checks out, you will display a message to the user with vbokonly that all is ready to process.

 

Processing:

 

When the command button to process is pressed, the quantity you entered is to be ADDED to the respective element in the Quantity Array. In other words your array is a running total keeper for each respective item.

 

Also you will call a small function, which you will call to calculate the amount of the item. The amount is equal to the number of days the item is late times the initial penalty fee that you have assigned in your variable.

 

This amount is ADDED to the respective element in the Amount Array.

 

Then prompt the user that the values have been entered into the arrays and then call a procedure to clear the form for another entry.

 

After the clearing, prompt the user that the form is ready.

 

You then will have a display button, which will use a For Next Loop to display the item name, the total items returned and total amounts.

 

While this display is being done, a final total for the quantity and amount should be run.

In other words you as you read each respective element in the arrays for display, you will add the value to respective variables and lastly display them on your display media.

 

Youll need a running total for the quantity and one for the amount.

 

Your display could look like this in a list box, if you choose to use a list box:

 

Item Quantity Amount

Hard Covered Books 100 25.00

Soft Covered Books 50 7.50

 

 

Final Totals 150 32.50

 

You will need a procedure to clear the form.

Remember you must use a For Next Loop to clear the control array.

 

You will also use a procedure to end the program.

 

You can code your own ending procedure or use the one I have at the end of this instruction document.

 

When you press the end command button. It should call this procedure. This procedure should be able to be called from anywhere in the program where you give the user the option to end.

 

You are to also have a clear button. This buttons click event should call the procedure to clear the form. The code to clear the button, just like in the end buttons click event should not be in the buttons click event anymore. The only code you should have in each of these buttons is the code to call the procedures to do these functions.

 

So, there should be four command buttons.

One to do the processing/ calling the function to calculate the amounts/ adding to the arrays etc.

One to clear, which calls a procedure to clear the form and which can be pressed anytime by the user.

One to Display the results which run the final totals as they display the details and ultimately print the final totals.

One to call the procedure to end.

 

Here is an example of an end procedure:

 

 

Here is the code, in the event the picture didnt take.

 

Private Sub End_Processing()

'Declare a variable to hold the message box response

 

Dim End_Response As String

 

'Give the user a chance not to end.

End_Response = MsgBox("Do you wish to end processing at this time?" & vbCrLf & _

"Press "" OK "" to end or cancel to continue.", _

vbOKCancel + vbQuestion, "Terminate Processing?")

'Perform terminating or non-terminating procedure depending on the user's response.

Select Case End_Response

Case Is = vbOK 'User chooses to terminate processing

MsgBox "Processing now terminating!", vbOKOnly + vbExclamation, _

"Terminating Program"

Unload Me

Case Else 'User chooses to reset and continue

MsgBox "Processing will reset all and continue"

Call Clear_Form

End Select

End Sub