繁体   English   中英

在Visual Basic(2010)分配中使用数组

[英]Using arrays in Visual Basic (2010) assignment

我正在为我的VB类做作业,我真的很辛苦,并且我非常感谢一些帮助,指针和/或示例。 我不希望得到确切的答案,但是类似的例子会很好。

CSV文件有5列,每列25行。 最主要的是,我需要获取最后两列并计算最后两行的标记,这两个都是十进制整数,并将其放入输出中。 换句话说,我有点需要将两列合并,然后将计算结果放在该列中。

这是作业:

应用标题:库存控制

目的:

该Windows MDI应用程序允许用户显示整个库存和计算售价,或显示带有其售价的库存中的选定项目。

程序:

用户将从主文档中选择全部或从菜单中选择。 相应的表格将显示在MDI窗口中。 如果用户选择了所有内容,则库存项目将简单地出现在列中,而售价则排在最后一列中。 如果用户选择了“选择”,则会出现一个选中的列表框,该列表框将允许用户选择她希望查看的清单项目。 然后,所选项目将显示在列中,而销售价格显示在最后一列中。 然后,用户应该能够使用“文件退出”菜单项退出程序。

算法,处理和条件:

  1. 用户从“显示”菜单中选择要如何显示清单
  2. 相应的表格已加载到MDI中
  3. 该程序从文件中读取数据
  4. 该程序通过将成本乘以1加上加价百分比来计算售价。
  5. 该程序设置标题和明细行的格式,并在列表框中的列中显示信息。

计划要求:

  1. 必须使用多文档界面
  2. 必须对库存物料使用类
  3. 必须使用父MDI表单上的菜单
  4. 除读取记录时使用的strRec数组外,必须至少使用其他数组。
  5. 可以使用arraylist和list来处理数据。

这是我到目前为止的代码:

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

感谢您的指导,建议和示例。

使用严格启用选项

这将显示您需要在InventoryItems.Reader中使用Dim IItem = New InvenItems ,这将显示另一个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM