For 循环后面的代码不会执行 - VB.NET
我这里有一个奇怪的问题。我在子程序中有一个 For 循环,在它的正下方有一个 MessageBox 函数。一切都正确编译,但是由于某种原因,如果循环执行并成功退出,则 For 之外和之下的任何内容都不会执行。
Public Sub Example()
For i = 0 To 9
ListBox.Items.Add(i.ToString)
Next
MessageBox.Show("Done") 'This doesn't execute
Beep() 'Doesn't either
Label.Text = "Done" 'etc.
End Sub
是的,之后列表框中只显示 10 个项目。
我到处搜索过,但没有找到与此类问题相关的任何内容。 我有点困惑,有人知道发生了什么事吗?
编辑:忘记指定,子实际上是一个 TextBox.TextChanged 事件
I'm having a strange issue here. I have a For loop inside a sub, and right below it I have a MessageBox function. Everything compiles correctly, however for some reason, if the loop executes and exits successfully, anything outside and below the For doesn't get executed.
Public Sub Example()
For i = 0 To 9
ListBox.Items.Add(i.ToString)
Next
MessageBox.Show("Done") 'This doesn't execute
Beep() 'Doesn't either
Label.Text = "Done" 'etc.
End Sub
Yes, it displays only 10 items in the ListBox afterwards.
I've searched everywhere, but I did not find anything related to such an issue.
I'm kinda puzzled, anyone got a clue of what's going on?
EDIT: Forgot to specify, the sub is actually a TextBox.TextChanged event
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来 ListBox.Items.Add 在最后一次迭代中包含空值。解决这个问题似乎就解决了。我不确定为什么它不会停止执行并返回错误(这里是新手)。
It seems the ListBox.Items.Add contained a null value on the last iteration. Fixing that seemingly solved it. I'm not sure why it wouldn't stop the execution and return an error (newbie here).