2

I'm doing an assignment for my VB class and I'm really having a tough time with it and I'd really appreciate some help, pointers, and/or examples. I don't expect to be just given the exact answer, but similar examples would be very good.

The CSV file has 5 columns each with 25 rows. The main thing is I need to take the last two columns and calculate the markup of the last two rows, both of which are Decimal integers, and put that in the output. In other words, I sort of need to combine the two columns and put the result of the calculation in that column.

Here is the assignment:

Application Title: Inventory Control

Purpose:

This Windows MDI application allows the user to display the entire inventory and calculate selling prices, or display selected items in inventory with their selling price.

Procedure:

From a main document the user will pick either All or Select from a menu. The appropriate form will display in the MDI window. If the user has chosen all, the inventory items will simply appear, arranged in columns with the selling price in the last column. If the use has chosen Select, a checked list box will appear which will allow the user to select the inventory items she wishes to see. The selected items will then display in columns with the selling price in the last column. The user should then be able to exit the program using the File Exit menu item.

Algorithms, Processing, and Conditions:

  1. The user chooses the how they want to display the inventory from the Display menu
  2. The appropriate form is loaded into the MDI
  3. The program reads the data from a file
  4. The program calculates the selling price by multiplying the cost times 1 plus the markup percentage.
  5. The program formats the heading and the detail lines and displays the information in columns in a list box.

Program requirements:

  1. Must use a multiple document interface
  2. Must use a class for the inventory items
  3. Must use a menu on the Parent MDI form
  4. Must use at least 1 array OTHER than the strRec array that you use when you read in the records.
  5. May use an arraylist and lists to process the data.

And here is the code I have so far:

Public Class frmMain

Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click 
    'Close the program
    Me.Close()
End Sub

Private Sub mnuHelpAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelpAbout.Click
    'Simple help box
    MessageBox.Show("Inventory control program. Version 1.0")
End Sub


Private Sub mnuInvenListAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuInvenListAll.Click
    'Create the child form the form
    Dim mdiChild1 As New frmAll
    'Set form as parent.
    mdiChild1.MdiParent = Me
    'display the form as Show
    mdiChild1.Show()
End Sub

Private Sub mnuInvenSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuInvenSelect.Click
    'Create the child for the form
    Dim mdiChild2 As New frmSelect
    'Set form as parent.
    mdiChild2.MdiParent = Me
    'display the form as Show
    mdiChild2.Show()
End Sub

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.LayoutMdi(MdiLayout.TileHorizontal)
End Sub

End Class


=-=-=-=-=


Imports System.IO
Imports System.Convert

Public Class frmAll
'Declare Streamreader
Private objReader As StreamReader


'Declare arrays to hold the information
Private strNumber(24) As String
Private strName(24) As String
Private strSize(24) As String


Private Sub frmAll_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    'Set objReader
    objReader = New StreamReader("products.csv")
    Call FillArray()
End Sub

Private Sub FillArray()
    'Declare variables and arrays

    Dim decCost(24, 1) As Decimal
    Dim strFields() As String
    Dim strRec As String
    Dim intCount As Integer = 0
    Dim chrdelim As Char = ToChar(",")
    'Set strRec to read the lines

    strRec = objReader.ReadLine

    'Do while loop to fill array.
    Do While strRec <> Nothing
        strFields = strRec.Split(chrdelim)
        strNumber(intCount) = strFields(0)
        strName(intCount) = strFields(1)
        strSize(intCount) = strFields(2)
        decCost(intCount, 0) = ToDecimal(strFields(3))
        decCost(intCount, 1) = ToDecimal(strFields(4))
        'Set strRec to read the lines again
        strRec = objReader.ReadLine
        'increment the index
        intCount += 1
    Loop
    Call Calculate(decCost)
End Sub

Private Sub Calculate(ByVal numIn(,) As Decimal)
    'Define arrays to hold total cost
    Dim decRowTotal(24) As Decimal

    'Define variables to hold the counters for rows and columns
    Dim intR As Integer
    Dim intC As Integer

    'Calcualte total cost
    For intC = 0 To numIn.Length
        For intR = 0 To decRowTotal.Length
            decRowTotal(intR) += numIn(intR, intC) * 1
        Next
    Next

    Call Output(numIn, decRowTotal)

End Sub

Private Sub Output(ByVal NumIn(,) As Decimal, ByVal RowTotalIn() As Decimal)
    Dim strOut As String

    Dim intR As Integer = 0
    Dim intC As Integer = 0

    strOut = "ID" & vbTab & "Item" & vbTab & "Size" & vbTab & "Total Price" & vbCrLf & vbCrLf

    For intR = 0 To 24
        strOut &= strNumber(intC) & vbTab
        strOut &= strName(intC) & vbTab
        strOut &= strSize(intC) & vbTab

        For intC = 0 To 1
            strOut &= NumIn(intR, intC).ToString
        Next

        strOut &= vbTab & RowTotalIn(intR) & vbCrLf
    Next

    rtbAll.Text = strOut

End Sub

End Class


-=-=-=-=-=


'Imports
Imports System.IO
Imports System.Convert

Public Class InventoryItems

'Declare ItemList Array
Private ItemList As New ArrayList
'IItem declared as new Object.
Private IItem As New Object

Public Function Reader() As ArrayList
    'Declare variables for reading the file.
    Dim chrDelim As Char = Convert.ToChar(",")
    Dim strRec As String
    Dim strFields() As String
    Dim objReader As StreamReader
    objReader = New StreamReader("products.csv")
    strRec = objReader.ReadLine
    'Declares a new instance of the InvenItems class
    'and stores each of the items in their own instance
    'of the class
    Do While strRec <> Nothing
        IItem = New InvenItems
        strFields = strRec.Split(chrDelim)
        IItem.Number = strFields(0)
        IItem.Name = strFields(1)
        IItem.Size = strFields(2)
        IItem.Price = ToDecimal(strFields(3))
        IItem.MarkUp = ToDecimal(strFields(4))
        ItemList.Add(IItem)
        strRec = objReader.ReadLine
    Loop

    Return ItemList
End Function

Public Class InvenItems
    'Declare class variables.
    Private strNumber As String
    Private strName As String
    Private strSize As String
    Private decCost As Decimal
    Private decMarkUp As Decimal
    'Create constructor
    Public Sub New()

    End Sub
    'Create override function
    Public Overrides Function ToString() As String
        Return strNumber
    End Function
    'Create property for Number.
    Public Property Number As String
        Set(ByVal value As String)
            strNumber = value
        End Set
        Get
            Return strNumber
        End Get
    End Property
    'Create property for Name.
    Public Property Name As String
        Set(ByVal value As String)
            strName = value
        End Set
        Get
            Return strName
        End Get
    End Property
    'Create property for size.
    Public Property Size As String
        Set(ByVal value As String)
            strSize = value
        End Set
        Get
            Return strSize
        End Get
    End Property
    'Create property for cost.
    Public Property Cost As Decimal
        Set(ByVal value As Decimal)
            decCost = value
        End Set
        Get
            Return decCost
        End Get
    End Property

    Public Property MarkUp As Decimal
        Set(ByVal value As Decimal)
            decMarkUp = value
        End Set
        Get
            Return decMarkUp
        End Get
    End Property

End Class

End Class

Thanks for any pointers, advice, and examples.

5
  • What problems, specifically, are you running into? The calculation, the form setup, errors? Commented Oct 6, 2012 at 18:10
  • It stops when I run the All form. It will run until I get to the first For loop. When it runs through that, it just ends. Also, I believe I have my loops wrong, and my arrays wrong, but I am unsure of what to set those to. Like I said, I'm still iffy on arrays. Commented Oct 6, 2012 at 18:16
  • By the first for loop, do you mean the one in Calculate? Can you set a breakpoint there to make sure that numIn contains what you're expecting? Commented Oct 6, 2012 at 18:41
  • Yes, I put a breakpoint in, and when I was Stepping In, it goes in, loops multiple times, and then when it ends it goes back to frmMain, ends, and diplays frmAll with nothing, not even the basic headers in the Rich Text Box. Commented Oct 6, 2012 at 18:58
  • @Brodoin As a quick check, you can add rtbAll.Visible = True after you set the text to it, just to make sure you can see the textbox. Commented Oct 9, 2012 at 13:05

1 Answer 1

1

Use Option Strict On.

This will show you that you need to use Dim IItem = New InvenItems in InventoryItems.Reader, and that will show another problem.

Sign up to request clarification or add additional context in comments.

4 Comments

I'll do that. What other problems are there? I posted this on a forum and a guy said my loops, especially my For loops, are totally off.
The other problems are for you to find ;) However, IMO part 4 of the question should read "The program calculates the selling price by multiplying the cost by (1 plus the markup fraction)."
@Brodoin Hint: frmAll does not use the InventoryItems class.
@Brodoin Your for loops look just fine to me. If the forum guy was expecting another language like C++, then he might not be the most helpful source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.