在我的主程序(形式),我有两个列表框,一个文本框和一个按钮。 当我挑中的每个列表框中的两个项目,并在文本框中输入一个数字,它是suppsoed在数组放养。 我想做到这一点使用一类。 (我只是问了这个问题,它的工作原理现在好了)。 问题是我想表现出不同形式的结果。 在我的课的代码如下所示:
Public Class Stocking
Public sale(3, 4) As Integer
Public numberSellers(3) As Integer
Public numberProducts(4) As Integer
Public Sub addItem(ByRef my_sellerListBox As ListBox, ByRef my_productListBox As ListBox, ByRef my_saleTextBox As TextBox)
Dim sellerLineInteger As Integer
Dim productColumnInteger As Integer
sellerLineInteger = my_sellerListBox.SelectedIndex
productColumnInteger = my_productListBox.SelectedIndex
' add in two dimensional array
If sellerLineInteger >= 0 And productColumnInteger >= 0 Then
sale(sellerLineInteger, productColumnInteger) = Decimal.Parse(my_saleTextBox.Text)
End If
my_saleTextBox.Clear()
my_saleTextBox.Focus()
For sellerLineInteger = 0 To 3
For productColumnInteger = 0 To 4
numberSellers(sellerLineInteger) += sale(sellerLineInteger, productColumnInteger)
Next productColumnInteger
Next sellerLineInteger
End Sub
Public Sub showItems(ByRef my_label)
my_label.Text = numberSellers(0).ToString 'using this as a test to see if it works for now
End Sub
End Class
我的主要形式如下:
Public Class showForm
Public sale(3, 4) As Integer
Public numberSellers(3) As Integer
Public numberProducts(4) As Integer
Dim StockClass As New Stocking
Public Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click
StockClass.addItem(sellerListBox, producttListBox, saleTextBox)
End Sub
Public Sub SalesByMonthToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalesByMonthToolStripMenuItem.Click
saleForm.Show()
而在我的第二个形式,展现放养在阵列中的结果:
Public Class saleForm
Dim StockClass As New Stocking
Public Sub saleForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
StockClass.showItems(Label00)
'Only using one label as a test for now.
End Sub
End Class
End Sub
我测试了它,并试图看看结果显示在主窗体上,它的作用。 所以我猜这个问题是我用不同的形式。 此外,我想可能是因为我在不同的形式再次调用类和不保留数据。