For 循环后面的代码不会执行 - VB.NET

发布于 2024-12-04 16:00:23 字数 499 浏览 7 评论 0原文

我这里有一个奇怪的问题。我在子程序中有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她比我温柔 2024-12-11 16:00:23

看来 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文