Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 在Visual Basic(2010)赋值中使用数组_Arrays_Vb.net_Visual Studio_Arraylist - Fatal编程技术网

Arrays 在Visual Basic(2010)赋值中使用数组

Arrays 在Visual Basic(2010)赋值中使用数组,arrays,vb.net,visual-studio,arraylist,Arrays,Vb.net,Visual Studio,Arraylist,我正在为我的VB课程做一个作业,我真的很辛苦,我真的很感谢一些帮助、指点和/或示例。我不希望得到确切的答案,但类似的例子会非常好 CSV文件有5列,每列25行。主要的是我需要取最后两列,计算最后两行的标记,这两行都是十进制整数,并将其放入输出中。换句话说,我需要将这两列合并,并将计算结果放在这一列中 以下是作业: 应用程序标题:库存控制 目的: 此Windows MDI应用程序允许用户显示整个库存并计算销售价格,或显示库存中的选定项目及其销售价格 程序: 用户将从主文档中选择全部或从菜单中选择。

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

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

以下是作业:

应用程序标题:库存控制

目的:

此Windows MDI应用程序允许用户显示整个库存并计算销售价格,或显示库存中的选定项目及其销售价格

程序:

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

算法、处理和条件:

  • 用户从显示菜单中选择他们想要显示库存的方式
  • 将适当的表单加载到MDI中
  • 程序从文件中读取数据
  • 该程序通过将成本乘以1加上加价百分比来计算销售价格
  • 程序将设置标题和详图线的格式,并在列表框的列中显示信息
  • 课程要求:

  • 必须使用多文档接口
  • 必须为库存项目使用一个类
  • 必须使用父MDI窗体上的菜单
  • 必须使用至少1个数组,而不是读取记录时使用的strec数组
  • 可以使用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
    
    公共类frmMain
    私有子mnuFileExit_Click(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理mnuFileExit。单击
    "关闭程序"
    我
    端接头
    私有子mnuHelpAbout_Click(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理mnuHelpAbout。单击
    “简单帮助框
    MessageBox.Show(“库存控制程序1.0版”)
    端接头
    私有子mnuinEventListall\u Click(ByVal发送方作为System.Object,ByVal e作为System.EventArgs)处理mnuinEventListall。单击
    '在窗体中创建子窗体
    将mdiChild1变为新的frmAll
    '将窗体设置为父级。
    mdiChild1.MdiParent=Me
    '将窗体显示为Show
    mdiChild1.Show()
    端接头
    私有子mnuInvenSelect\u单击(ByVal发送方作为System.Object,ByVal e作为System.EventArgs)处理mnuInvenSelect。单击
    '为窗体创建子级
    Dim mdiChild2作为新FRM选择
    '将窗体设置为父级。
    mdiChild2.MDIPRENT=Me
    '将窗体显示为Show
    mdiChild2.Show()文件
    端接头
    私有子frmMain_Load(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理MyBase.Load
    Me.LayoutMdi(MdiLayout.TileHorizontal)
    端接头
    末级
    =-=-=-=-=
    导入System.IO
    导入系统。转换
    公共类购物中心
    '声明Streamreader
    作为StreamReader的私有objReader
    '声明数组以保存信息
    私有strNumber(24)作为字符串
    私有strName(24)作为字符串
    私有字符串(24)作为字符串
    私有子frmAll_Load(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理MyBase.Load
    '设置objReader
    objReader=newstreamreader(“products.csv”)
    调用FillArray()
    端接头
    私有子数组()
    '声明变量和数组
    十进制成本(24,1)
    Dim strFields()作为字符串
    作为字符串的Dim strRec
    Dim intCount作为整数=0
    Dim chrdelim为Char=ToChar(“,”)
    '设置strRec以读取行
    strRec=objReader.ReadLine
    '执行while循环以填充数组。
    什么都不做,什么都不做
    标准字段=标准拆分(chrdelim)
    strNumber(intCount)=strFields(0)
    strName(intCount)=strFields(1)
    strSize(intCount)=标准字段(2)
    decost(intCount,0)=ToDecimal(strFields(3))
    decCost(intCount,1)=ToDecimal(strFields(4))
    '设置strRec以再次读取行
    strRec=objReader.ReadLine
    '增加索引
    整数计数+=1
    环
    呼叫计算(成本)
    端接头
    专用子计算(ByVal numIn(,)作为十进制)
    '定义数组以保存总成本
    Dim decRowTotal(24)为十进制
    '定义用于保存行和列计数器的变量
    作为整数的Dim intR
    作为整数的Dim intC
    “计算总成本
    对于intC=0到最小长度
    对于intR=0,则减小总长度
    decRowTotal(intR)+=numIn(intR,intC)*1
    下一个
    下一个
    调用输出(numIn,decRowTotal)
    端接头
    私有子输出(ByVal NumIn(,)作为十进制,ByVal RowTotalIn()作为十进制)
    像弦一样的暗弦
    Dim intR作为整数=0
    Dim intC作为整数=0
    strOut=“ID”&vbTab&“项目”&vbTab&“尺寸”&vbTab&“总价”&vbCrLf&vbCrLf
    对于intR=0到24
    strOut&=strNumber(intC)和vbTab
    strOut&=strName(intC)和vbTab
    strOut&=strSize(intC)和vbTab
    对于intC=0到1
    strOut&=NumIn(intR,intC).ToString
    下一个
    strOut&=vbTab&RowTotalIn(intR)&vbCrLf
    下一个
    rtbAll.Text=strOut
    端接头
    末级
    -=-=-=-=-=
    "进口",
    导入System.IO
    导入系统。转换
    公共类清单项