Return Home Members Area Experts Area The best AskMe alternative!Answerway.com - You Have Questions? We have Answers! Answerway Information Contact Us Online Help
 Thursday 8th January 2009 01:28:45 PM


 

Username:

Password:

or
Join Now!

 

Home/Computing Technology/Programming/Visual Basic

Forum Ask A Question   Question Board   FAQs Search
Return to Question Board

Question Details Asked By Asked On
visual basic hotpotato 03/15/05
    Hi expert! I'm working on an activity for class and I have some truoble coding. Below i have included the instructions and i would like you to check my code for me. IT is programmed in vbnet Can you help me to fix it?
    thank you!

    Qustion:
    Use the attached text file “products.txt”. Read the data into 3 arrays to hold the product name, unit price and quantity on hand. The data looks like this:

    Name Unit Price Qty

    Widgets 11.00 100
    Sprockets 5.65 35
    Thingees 207.99 10
    Googlies 75.00 3
    Zubbes 19.50 27


    Once the data is fully loaded, display a completion message. Allow the user to enter orders i.e. a product name and an order qty. The order qty will be validated for a numeric
    value. An order number will be assigned by the program starting from 10001 and the order will be processed as follows:

    If the product is found and there is sufficient quantity on hand to fully meet the order, then the order is filled. The amount due will be calculated (qty * price) and the quantity on hand decremented by the qty ordered. The result of the order will be displayed in a message box e.g.

    Order# 0002 for 13 Widgets completed.

    The order detail will be added to 4 arrays to contain Order#, Product,QtyOrdered and Amount Due.

    If the order cannot be completed because:
    1) Product not found
    2) Insufficient Qty on hand to fully meet the order

    then an appropriate message box will be displayed and no further action taken

    When all orders have been processed the program will optionally display all processed orders in a list box – see sample below

    Orders Processed

    Order # Product Qty Amount Due

    0001 Widgets 10 $110.00
    0002 Sprockets 5 $28.70
    0003 Widgets 26 $260.00

    Total Value of Orders $398.70

    ======================
    here is my code:

    Dim names(5) As String
    Dim unit_price(5) As Double
    Dim quantity(5) As Integer
    Dim order_number(100) As Integer
    Dim product(100) As String
    Dim QtyOrdered(100) As Integer
    Dim AmountDue(100) As Double

    Dim count As Integer
    Dim k As Integer
    Private Sub btnReadProductFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadProductFile.Click

    Dim product_file As IO.StreamReader

    product_file = IO.File.OpenText("Products.txt")
    'Dim fmtStr As String = "{0, -12} {1, -11} {2, -20}"


    lstOutput.Items.Add(String.Format(fmtStr, "Product", "Unit Price", "Qty"))
    Do While product_file.Peek <> -1
    names(count) = product_file.ReadLine
    unit_price(count) = CInt(product_file.ReadLine)
    quantity(count) = CInt(product_file.ReadLine)

    Dim fmtStr1 As String = "{0, -12} {1, -11} {2, -22}"
    'lstOutput.Items.Add(String.Format(fmtStr1, names(k), unit_price(k), quantity(k)))
    Loop
    MsgBox("Complete! All data is loaded!", MsgBoxStyle.Information, "Completion")
    product_file.Close()
    End Sub



    Private Sub btnEnterOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnterOrder.Click
    Dim product As String
    Dim quantity As Integer



    product = txtProductName.Text
    quantity = CInt(txtOrderQuantity.Text)

    For k = quantity To count - 1
    If txtProductName.Text = CStr(lstOutput.Items(k)) And txtOrderQuantity.Text > CStr(lstOutput.Items(k)) Then
    AmountDue(k) = CDbl(quantity) * unit_price(k)
    quantity = QtyOrdered(k) - quantity

    Else
    MsgBox("Product found but Insufficient quantity to meet the order!", MsgBoxStyle.Critical, "Insufficient Quantity")
    End If
    Next k

    End Sub

    Private Sub txtOrderQuantity_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtOrderQuantity.Validating
    If txtOrderQuantity.Text = "" Then
    MsgBox("Please enter a quantity!", MsgBoxStyle.Critical, "Quantity Request")
    txtOrderQuantity.SelectAll()
    e.Cancel = True
    End If
    If IsNumeric(txtOrderQuantity.Text) = False Then
    MsgBox("Enter a valid number of order quantity!", MsgBoxStyle.Critical, "Invalid Quantity")
    txtOrderQuantity.SelectAll()
    e.Cancel = True
    Else
    quantity(k) = CInt(txtOrderQuantity.Text)
    End If
    End Sub

Summary of Answers Received Answered On Answered By Average Rating
1. Hi hotpotato If I could I would have loved to help You But...
03/16/05 Pride_of_AlderabanExcellent or Above Average Answer
Your Options
    Additional Options are only visible when you login! !

vq/Vi   © Copyright 2002-2008 Answerway.org. All rights reserved. User Guidelines. Expert Guidelines.
Privacy Policy. Terms of Use.   Make Us Your Homepage
. Bookmark Answerway.