0

我有一个richTextbox和一个while循环,x = 0,每次这个循环运行时,x += 1直到它达到某个值。

这就是我想要发生的事情:
while x <> 10 then 它会item 0 +1在新行上说,然后item 1 + 1在它下面的行上,等等,所以你会在之后看到所有 10 个值。

发生的情况是,它将将该行更改为新值。

我的问题是:我如何让它把单词放在一个新的行上?

这是我的代码:

While readListItem <> PaymentList.Items.Count
    If readListItem > PaymentList.Items.Count Then
        readListItem = 0
        Exit While
    End If
    readListItem += 1
    MessageBox.Show(readListItem)
    resultBox.Text = vbNewLine + PaymentList.Items.Item(readListItem) + " costs " + enteredCost + "." + vbNewLine
End While

readListItem是“x”,每次循环运行时都会被迭代 1 PaymentList是我的列表框,其中包含一个未知值(用户设置此列表中的项目数)

The If if there because, after x = let say 10, it would add another to x (so now it = 11) and try print out the 11th item, as it doesn't exist, it crash. 这是为了防止这种情况发生。我不想尝试一下

4

1 回答 1

2

尝试添加新值而不是替换整个值:

resultBox.Text &= Environment.NewLine() & PaymentList.Items.Item(readListItem) + " costs " + enteredCost + "."

在这种情况下,表达式&=等价于resultBox.Text = resultBox.Text & "..."

一旦得到建议,您可以通过使用以下条件来简化循环:

While readListItem < PaymentList.Items.Count
    '...
End While
于 2013-07-16T05:18:05.730 回答