【问题标题】:MsgBox doesn't stop the codeMsgBox 不会停止代码
【发布时间】:2014-08-11 11:57:36
【问题描述】:

我有一个 onChange TextBox 事件。当 textlength 为 22 时,应该显示一个 msgbox 并且应该建立一个数据库连接。

不幸的是,msgbox 没有出现,或者出现和消失的速度非常快。

不应该这样发生。我也尝试过使用 ApplicationModal 但这并没有改变任何东西。

示例代码:

Private Sub txt_Auftrag_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_Auftrag.TextChanged

    If Len(txt_Auftrag.Text) = 22 Then 'txt_Auftrag.TextLength = 22 Then
        MsgBox("In der If", MsgBoxStyle.ApplicationModal Or MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        var_Aufrag = Mid(txt_Auftrag.Text, 15, 8)


        '------------------------------------------SET dbConnection
        Dim myConn As SqlConnection
        Dim myCmdText As String

        Try
            Cursor.Current = Cursors.WaitCursor
            myConn = New SqlConnection("Data Source=127.0.0.1;Initial Catalog=db;User ID=dbadm;Password=pw")
            myConn.Open() 
            lbl_Auftrag_Value.Text = var_Aufrag
            Cursor.Current = Cursors.Default
        Catch ex As Exception
            Cursor.Current = Cursors.Default
            MsgBox("Verbindung zur Datenbank konnte nicht hergestellt werden. Kontaktieren Sie den Administrator. Fehlerbeschreibung: " & ex.Message)
            var_Aufrag = Nothing
            txt_Auftrag.Text = Nothing

            Exit Sub
        End Try

        MsgBox("ConnGood")

【问题讨论】:

  • 虽然提供示例代码很好,但您能提供您的实际代码吗?
  • 你有没有使用调试器检查If txt_Something.Text Length = 22中的代码是否被执行?
  • 如果 Statement 被执行,代码将(现在)在 catch 块中。还有一个MsgBox,这次被执行了……
  • 正如@overmind 所说,您需要发布您正在使用的实际代码。我们都可以在您的帖子中看到印刷错误,这些错误会立即告诉我们它甚至不会像那样编译!如果你“登陆”Catch,那有什么例外??
  • 我使用了If TextBoxName.Text.Length = 22 Then MsgBox("Hello", MsgBoxStyle.ApplicationModal) Else End If,对我来说效果很好。调试时会发生什么?

标签: vb.net msgbox


【解决方案1】:

我想我明白了。我正在为 MDT 设备编程并用它扫描条形码。当输入等于 22 个符号的文本时,会出现 msgbox。扫描条形码时,如果我的手指在扫描按钮上,则开始执行 If 语句,然后通过释放它,单击 msgbox。总之很奇怪:)

谢谢,再见

【讨论】:

  • 通过在这个之后放置另一个 msgbox 来证明它......并且第二个弹出就像它应该的那样......我想我应该使用一个线程左右......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-03
  • 1970-01-01
相关资源
最近更新 更多