Good Day,

Part 1:

Program Discussion

The first question was to construct an order form utilizing various textboxes for user input and calculating an order. The first section of inputs is for a customer’s shipping information: name, address, city, state, and zip code. Next, the specific description, quantity, and price of each item are to be inputted individually, as well as selecting the shipping option. The last three boxes display the subtotal, shipping charge, and order total. In the form, you may want to organize and group the textboxes by relevance, creating four basic sections: customer info, item info, shipping, and totals. It should be added a drop-down list for the state abbreviations instead of a textbox because this is the more likely format encountered. Included are two radio selection buttons distinguishing between ground and express shipping. The three buttons at the bottom of the form(from left to right) respectively calculate each item’s price and clear the item info, calculate and display the order totals and clear the form, and exit the form program.

When developing the code for each button a few issues that can be challenging such as: First, the IF statements within the TRY segment for the “Next Item” button did not always function logically. When the conditions were appropriate, the only thing calculated was the shipping and it was only based on the price of the first item. It seemedquantities weren’t adding up and the running totals were not being saved because either they were cleared later in the code or there was a conflict of variables. Then changed the way the variables were input from the textboxes by using the “Integer.parse()” and “Decimal.parse()” commands. It is also should be realized that the variables kept clearing because they weren’t defined properly at the beginning of the form. You should switch them from “Public” to “Private.” Because of all this, when the “New Order” button was pressed, the message box appeared correctly with all the customer data, but with the incorrect quantity and totals. This also stemmed back to some disorderly code in the “Next” button which later you should edited to remove the shipping IF statement tree from the error-catching TRY segment. Once the major issues were corrected, then added two lines in the “New order” subroutine to clear the running total variables: quantTotal and subTotal by setting them to zero. Refer to the Order Form’s VB code on the next page.

Part 1 Screenshots: Entering the test data

To the right is a shot of all the preliminary data entered in the form including customer info, item info and with ground shipping selected. After clicking the “Next Item” button, only the bottom of the form changes and displays the current totals (inset right) while the item info is cleared:

Then the second item info is inputted and if the “Next Button” is clicked, the desired totals can be viewed again, however this is not necessary. As seen below (and inset):

Once the last item is inputted, the user can click the “New Order” button and view that last order information in a message box. Upon clicking “OK,” the user is returned to the blank form to start another order.

Part 1:VB Code

'Project: Midterm Project

'Date:

'Description: For Question 1: A basic order form that requests a

' customer's info as well as item info for multiple items, then

' calculates the totals for shipping and the complete order.

PublicClass Form1

'Defining the input data as variables or strings.

Private custname, address, city, state, zip AsString

Private quantity, price AsInteger

Private itemTotal, quantTotal, subTotal, shipTotal, grandTotal AsDecimal

PrivateSub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click

'This button stores the current input information and clears

'only the "Item Info" section so a new item can be added.

custname = nameBox.Text

address = addyBox.Text

city = cityBox.Text

state = stateBox.Text

zip = zipBox.Text

'This segment sets the restrictions on what values can be

'entered into the item boxes:

Try

'Clears the appropriate textboxes and focuses on where

'the error was.

If IsNumeric(quantBox.Text) = FalseThen

MsgBox("Quantity Invalid")

quantBox.Focus()

ElseIfCInt(quantBox.Text) <= 0 Then

MsgBox("Quantity Invalid")

quantBox.Focus()

ElseIf IsNumeric(priceBox.Text) = FalseThen

MsgBox("Price Invalid")

priceBox.Focus()

ElseIfCDec(priceBox.Text) < 0 Then

MsgBox("Price Invalid")

priceBox.Focus()

EndIf

Catch'For any other bad data found.

MessageBox.Show("Unexpected Error")

EndTry

'Saving values from textboxes to variables.

quantity = Integer.Parse(quantBox.Text)

price = Decimal.Parse(priceBox.Text)

'Calculating the item subtotal based on quntity and price.

itemTotal = quantity * price

subTotal += itemTotal

quantTotal += quantity

--(continued on next page)--

'The shipping charge is determined from the subtotal and varies

'according to price and whether ground or express is selected.

WithMe

If subTotal < 15.0 Then

If groundButton.Checked Then

shipTotal = 4.95

ElseIf expressButton.Checked Then

shipTotal = 14.95

EndIf

ElseIf subTotal >= 15.0 And subTotal <= 49.99 Then

If groundButton.Checked Then

shipTotal = 6.95

ElseIf expressButton.Checked Then

shipTotal = 16.95

EndIf

ElseIf subTotal >= 50.0 And subTotal <= 99.99 Then

If groundButton.Checked Then

shipTotal = 8.95

ElseIf expressButton.Checked Then

shipTotal = 18.95

EndIf

ElseIf subTotal >= 100.0 And subTotal <= 199.99 Then

If groundButton.Checked Then

shipTotal = 10.95

ElseIf expressButton.Checked Then

shipTotal = 20.95

EndIf

ElseIf subTotal >= 200.0 Then

If groundButton.Checked Then

shipTotal = 12.95

ElseIf expressButton.Checked Then

shipTotal = 22.95

EndIf

EndIf

EndWith

'The totals are calculated and converted to dollar amounts.

grandTotal = subTotal + shipTotal

subBox.Text = subTotal.ToString("C")

shipBox.Text = shipTotal.ToString("C")

totalBox.Text = grandTotal.ToString("C")

'Clearing the item boxes for the next item.

WithMe

.descBox.Clear()

.quantBox.Clear()

.priceBox.Clear()

With .descBox

.Focus()

EndWith

EndWith

EndSub

--(continued on next page)--

PrivateSub NewButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewButton.Click

'This button shows the current order summary in a message box

'and clears all the fields and the current order values.

'Defining the customer info for the message box.

custname = nameBox.Text

address = addyBox.Text

city = cityBox.Text

state = stateBox.Text

zip = zipBox.Text

'Shows the recent order details in a message box.

Dim messageString AsString

messageString = custname _

& ControlChars.NewLine & ControlChars.NewLine _

& address _

& ControlChars.NewLine & ControlChars.NewLine _

& city & ", " & state & " " & zip _

& ControlChars.NewLine & ControlChars.NewLine _

& "Items ordered: " & quantTotal _

& ControlChars.NewLine & ControlChars.NewLine _

& "Subtotal: " & subTotal.ToString("C") _

& ControlChars.NewLine & ControlChars.NewLine _

& "Shipping: " & shipTotal.ToString("C") _

& ControlChars.NewLine & ControlChars.NewLine _

& "Total: " & grandTotal.ToString("C")

MessageBox.Show(messageString, "Order Details")

'Sets the running totals to zero for the new order.

subTotal = 0

quantTotal = 0

'These lines clear and reset all the fields of the form to start again.

WithMe

nameBox.Clear()

addyBox.Clear()

cityBox.Clear()

stateBox.SelectedItem = Nothing

zipBox.Clear()

descBox.Clear()

quantBox.Clear()

priceBox.Clear()

groundButton.Checked = False

expressButton.Checked = False

subBox.Clear()

shipBox.Clear()

totalBox.Clear()

EndWith

EndSub

PrivateSub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click

'This button closes the form.

Me.Close()

EndSub

EndClass

PART 2: Program Discussion

The second question, deviating from the first, utilizes menus and programmed functions instead of buttons for much of the calculation work. The customer and item input data, however, are the same. The added functions are a Menu Strip, Color Dialogue, and Font Dialogue which regulate thetext-editing and informational menus with more options. For this modified order form, you should keep the same general look and functionality of the first one with a few differences. The “State” input box has reverted to a regular text box instead of a drop-down menu, the three buttons that were on the bottom are now located as functions within the “Order” menuu on the top bar. Added to the menu bar are an “Edit” menu where the font and color of the total boxes can be changed as well as a “Help” menu displaying an “about” message when clicked. It is also should be decided to eliminate the “Shipping” section and instead put it in the menu bar as its own checklist. By default, ground shipping will be selected.

After inputting the customer’s info and the first item’s info, clicking the “New Item” line in the Order menu will calculate the totals on the bottom of the form. Clicking the “Order Complete” line will bring up the summary and totals in a message box much like the first form. This form was not without its issues either. Oddly, sometimes the shipping total is calculated and displayed at the bottom when the “Next Item” line is clicked and sometimes not, even though the correct shipping cost and total are always displayed in the message box after selecting “Order Complete.” This may be because of the location of the shipping functions for the GroundShip and ExpressShip subroutines within the form’s code. They are after all the other calculations done in the NewItem and NewOrder subroutines. Perhaps writing the shipping code as separate function procedures within the “Public” class could have changed that behavior. You may or may not include separate function procedures because. The majority of code was taken from the previous form and separated to accommodate the menu format. Also the error-handling within NewItem’s TRY segment generates problems in the debug mode when letters are inputted instead of numbers. Not sure why that is and could not find a suitable solution. As long as numbers are inputted, the program works.

Part 2 Screenshots: Exploring the menus and options(next page)

All of the data entry works the same as in the first form, but the button functions are now located nicely in the menu bar. Here’s a look at how the menus are set up when clicked on:

Under the “Edit” menu, the user can change the font and color of the test in the last three total summary boxes when prompted:

Shown above are the totals when the color red and bold font are selected. When the “Help” menu is selected, the user can choose the about line and view a small message box outlining the form, its creator, and creation date:

Once again, as in the first form, the “New Order” function will display the running totals and customer info in a small message box before clearing the form for another order:

For the complete VB code of Order Form 2, see the next few pages.

Part 2: VB Code

'Project: Midterm Project

'Date:

'Description: For Question 2: A basic order form that requests a

' customer's info as well as item info for multiple items, then

' calculates the totals for shipping and the complete order,

' this time using drop-down menus and functions.

PublicClass Form1

'Defining the values used in the form.

Private custname, address, city, state, zip AsString

Private quantity, price AsInteger

Private itemTotal, quantTotal, subTotal, shipTotal, grandTotal AsDecimal

PrivateSub NewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewItem.Click

'Stores the previous item values and clears the item info

'section for a new item input.

custname = nameBox.Text

address = addyBox.Text

city = cityBox.Text

state = stateBox.Text

zip = zipBox.Text

'This segment sets the restrictions on what values can be

'entered into the item boxes and handles bad data:

Try

'Clears the appropriate textboxes and focuses on where

'the error was.

If IsNumeric(quantBox.Text) = FalseThen

MsgBox("Quantity Invalid")

quantBox.Focus()

ElseIfCInt(quantBox.Text) <= 0 Then

MsgBox("Quantity Invalid")

quantBox.Focus()

ElseIf IsNumeric(priceBox.Text) = FalseThen

MsgBox("Price Invalid")

priceBox.Focus()

ElseIfCDec(priceBox.Text) < 0 Then

MsgBox("Price Invalid")

priceBox.Focus()

EndIf

Catch'For any other bad data found.

MessageBox.Show("Unexpected Error")

EndTry

'Saving values from textboxes to variables.

quantity = Integer.Parse(quantBox.Text)

price = Decimal.Parse(priceBox.Text)

'Calculating the item subtotal based on quntity and price.

itemTotal = quantity * price

subTotal += itemTotal

quantTotal += quantity

--(continued on next page)--

'The totals are calculated and converted to dollar amounts.

grandTotal = subTotal + shipTotal

subBox.Text = subTotal.ToString("C")

shipBox.Text = shipTotal.ToString("C")

totalBox.Text = grandTotal.ToString("C")

'Clearing the item boxes for the next item.

WithMe

.descBox.Clear()

.quantBox.Clear()

.priceBox.Clear()

With .descBox

.Focus()

EndWith

EndWith

EndSub

PrivateSub NewOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewOrder.Click

'Calculates the order totals and displays them in a message box,

'then clears the form to begin a new order.

'Defining the customer info for the message box.

custname = nameBox.Text

address = addyBox.Text

city = cityBox.Text

state = stateBox.Text

zip = zipBox.Text

'Shows the recent order details in a message box.

Dim messageString AsString

messageString = custname _

& ControlChars.NewLine & ControlChars.NewLine _

& address _

& ControlChars.NewLine & ControlChars.NewLine _

& city & ", " & state & " " & zip _

& ControlChars.NewLine & ControlChars.NewLine _

& "Items ordered: " & quantTotal _

& ControlChars.NewLine & ControlChars.NewLine _

& "Subtotal: " & subTotal.ToString("C") _

& ControlChars.NewLine & ControlChars.NewLine _

& "Shipping: " & shipTotal.ToString("C") _

& ControlChars.NewLine & ControlChars.NewLine _

& "Total: " & grandTotal.ToString("C")

MessageBox.Show(messageString, "Order Details")

'Sets the running totals to zero for the new order.

subTotal = 0

quantTotal = 0

'These lines clear and reset all the fields of the form to start again.

WithMe

nameBox.Clear()

addyBox.Clear()

cityBox.Clear()

stateBox.Clear()

--(continued on next page)--

zipBox.Clear()

descBox.Clear()

quantBox.Clear()

priceBox.Clear()

GroundShip.Checked = True

ExpressShip.Checked = False

subBox.Clear()

shipBox.Clear()

totalBox.Clear()

nameBox.Focus()

EndWith

EndSub

PrivateSub ExitForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitForm.Click

'Closes the order form.

Me.Close()

EndSub

PrivateSub GroundShip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroundShip.Click

'Changes the shipping method and related charges to ground.

'this is the default value for the form.

'Only one shipping method can be selected at once.

If GroundShip.Checked = TrueThen

ExpressShip.Checked = False

EndIf

'The various conditions for ground:

If subTotal < 15.0 Then

shipTotal = 4.95

ElseIf subTotal >= 15.0 And subTotal <= 49.99 Then

shipTotal = 6.95

ElseIf subTotal >= 50.0 And subTotal <= 99.99 Then

shipTotal = 8.95

ElseIf subTotal >= 100.0 And subTotal <= 199.99 Then

shipTotal = 10.95

ElseIf subTotal >= 200.0 Then

shipTotal = 12.95

EndIf

EndSub

PrivateSub ExpressShip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExpressShip.Click

'Changes the shipping method and related charges to express.

'Only one shipping method can be selected at once.

If ExpressShip.Checked = TrueThen

GroundShip.Checked = False

EndIf

'The various conditions for express:

If subTotal < 15.0 Then

shipTotal = 14.95

ElseIf subTotal >= 15.0 And subTotal <= 49.99 Then

shipTotal = 16.95

ElseIf subTotal >= 50.0 And subTotal <= 99.99 Then

--(continued on next page)--

shipTotal = 18.95

ElseIf subTotal >= 100.0 And subTotal <= 199.99 Then

shipTotal = 20.95

ElseIf subTotal >= 200.0 Then

shipTotal = 22.95

EndIf

EndSub

PrivateSub TextColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextColor.Click

'Changes the color of the order totals summary text.

'Dim OrderMessage As String

WithMe.ColorDialog1

.Color = Me.subBox.ForeColor

.ShowDialog()

Me.subBox.ForeColor = .Color

Me.shipBox.ForeColor = .Color

Me.totalBox.ForeColor = .Color

EndWith

EndSub

PrivateSub FontItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontItem.Click

'Changes the font of the order totals summary text.

'Dim OrderMessage As String

WithMe.FontDialog1

.Font = Me.subBox.Font

.ShowDialog()

Me.subBox.Font = .Font

Me.shipBox.Font = .Font

Me.totalBox.Font = .Font

EndWith

EndSub

PrivateSub AboutForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutForm.Click

'Displays the general properties of the form.

Dim messageString AsString

messageString = "Program: Order Form 2" _

& ControlChars.NewLine & ControlChars.NewLine _

& "Version: 1.0.0" _

& ControlChars.NewLine & ControlChars.NewLine _

& "Designed by: J.M.Parmley" _

& ControlChars.NewLine & ControlChars.NewLine _

& "Date: 10-16-2010" _

& ControlChars.NewLine & ControlChars.NewLine

MessageBox.Show(messageString, "About Order Form 2")

EndSub

EndClass