Write an application that calculates the cost of all the


Write an application that calculates the cost of all the supplies added to the user's shopping list (Fig. 22.18). The application

should contain two Li stBoxes. The first contains all the supplies offered and their respective prices. Users should be able to

select the desired supplies from the first Li stBox and add them to the second Li stBox. Provide a Calculate Button that

displays the total price for the user's shopping list (the contents of the second ListBox).

a) Copying the template to your working directory. Copy the directory C: ExamplesTutori al 22Exerci sesSuppl yCal cul ator to

your C: Si mpl yVB2008 directory.

b) Opening the application's template file. Double click Suppl yCal cul ator. sl n in the Suppl yCal cul ator directory to open the

application.

c) Adding code to the Add >> Button. Double click the Add >> Button to create an empty event handler. Insert code in the

event handler that adds the selected item from the first Li stBox to shoppi ngLi stBox. Be sure to check that an item is selected

in the first Li stBox before attempting to add an item to shoppi ngLi stBox.

d) Enabling the Buttons. Once the user adds something to the shoppi ngLi stBox, set the Enabl ed properties of the <<

Remove and Calculate Buttons to True.

e) Deselecting the items. Once the item is added to the shoppi ngLi stBox, make sure that it is deselected in the stockLi

stBox. Also, clear the Total: Label to indicate to the user that a new total price must be calculated.

f) Adding code to the << Remove Button. Double click the << Remove Button to create an empty event handler. The Items in

your list: Li stBox's Sel ecti onMode property has been set to Mul ti Extended to allow the user to select multiple items. Use a

Do Whi l e loop to remove any selected items in the shoppi ngLi stBox. Be sureto check that at least one item is selected

before attempting to remove an item. [Hint:Method shoppi ngLi stBox. Items. RemoveAt(i ndex) will remove the item located

at i ndex from the shoppi ngLi stBox. When an item is removed, the Sel ectedIndexproperty points to the next selected item,

if there is one.] If there are no items remaining in the shoppi ngLi stBox, disable the << Remove and Calculate Buttons.Also,

clear the Total: Label to indicate to the user that a new total price must be calculated.

g) Adding code to the Calculate Button. Double click the Calculate Button to create an empty event handler. Use a For... Next

statement to loop through all the items in the shoppi ngLi stBox. Convert each item from the Li stBox into a Stri ng. Then use

the Stri ng method Substri ng to extract the price of each item.

h) Displaying the total. Convert the Stri ng representing each item's price to a Decimal , and add this to the overall total (of

type Deci mal ). Remember to output the value in currency format.

i) Running the application. Select Debug > Start Debugging to run your application. Use the Add >> and << Remove Buttons to

add and remove items from the Items in your list: Li stBox. Click the Calculate Button and verify that the total price displayed

is correct.

j) Closing the application. Close your running application by clicking its close box.

k) Closing the IDE. Close the Visual Basic IDE by clicking its close box.

1103_p1.png


Attachment:- Tutorial22.zip

Solution Preview :

Prepared by a verified Expert
Programming Languages: Write an application that calculates the cost of all the
Reference No:- TGS01242466

Now Priced at $20 (50% Discount)

Recommended (94%)

Rated (4.6/5)