【发布时间】:2015-04-10 22:24:34
【问题描述】:
我对 vb.net 和一般编程非常陌生,所以我希望我能得到一个非常简单的答案。
我编写了一个输入框,用于检索用户输入并将其存储在变量 salesQty 中。
salesQty =
InputBox("Enter the sales quantity for " & itemListBox.Text, "Daily Sales Entry", "0")
之后,我尝试将 Listbox 的 text 属性设置为等于 salesQty(假设它会更改所选项目的显示文本),但它似乎根本没有改变。
salesQtyListBox.Text = salesQty
这是完整的代码:
Private Sub enterSalesQtyButton_Click(sender As Object, e As EventArgs) Handles enterSalesQtyButton.Click
'Retrieve number of items in itemList Box and sets it as variable numItems
Dim numItems As Integer = itemListBox.Items.Count
'Declare index to use as counter
Dim index As Integer
Do While index < numItems
index = index + 1
Dim salesQty As String
salesQty =
InputBox("Enter the sales quantity for " & itemListBox.Text, "Daily Sales Entry", "0")
'Changes Sales Quantity text to the users input that has been stored in SalesQty
salesQtyListBox.Text = salesQty
'Selects next index until all have been selected
If itemListBox.SelectedIndex < numItems - 1 Then
itemListBox.SelectedIndex = itemListBox.SelectedIndex + 1
End If
Loop
enterSalesQtyButton.Enabled = False
applyDailySalesButton.Enabled = True
End Sub
【问题讨论】:
-
你试过用我的代码做吗?它有效吗?如果不是,我很乐意根据您的 cmets 尝试修复它。
-
您好,抱歉回复晚了!有点忙。我确实尝试了您的代码,但没有使用它,因为我实际上特别想使用 Do While 而不是 For Next。但是,我确实从中得到了提示!例如,我不知道 itemListBox.Items(i) = 是一个东西,我最终用 salesQtyListBox.Items(salesQtyListBox.SelectedIndex) = salesQty 替换了 salesQtyListBox.Text = salesQty 以及其他清理方法!