1

我最近遇到了一个问题,如果我用 msgbox.styleyesno 调用 sub,它不会回到调用它的原始 sub。

这是我的代码:Sub1:

Private Sub cmbLeegmaken_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbLeegmaken.SelectedIndexChanged
    Tabel_Leegmaken(cmbLeegmaken.Text)
    Hide_Leegmaken()
    Loadtable()
End Sub

称为子:

Sub Tabel_Leegmaken(ByVal Tabelnaam As String)
    MsgBox("Weet je zeker dat je de tabel " & Tabelnaam & " volledig wilt leegmaken?", MsgBoxStyle.YesNo)
    If vbYes Then
        Dim QuerVerwijdertabel As New SqlCommand("TRUNCATE TABLE " & Tabelnaam, connection)
        QuerVerwijdertabel.ExecuteNonQuery()
    End If
End Sub

问题是,在 sub Tabel_Leegmaken 结束后,它不会返回到“Private Sub cmbLeegmaken_SelectedIndexChanged”。

我不知道它是否与在那里调用 msgbox 有什么关系,但我似乎无法让它工作(尽管这可能是一些我似乎无法发现的小错误 > <)。

提前致谢!

4

2 回答 2

1

我想你的意思是写:

Sub Tabel_Leegmaken(ByVal Tabelnaam As String)
    If MsgBox("Weet je zeker dat je de tabel " & Tabelnaam & " volledig wilt leegmaken?", MsgBoxStyle.YesNo) = vbYes Then
        Dim QuerVerwijdertabel As New SqlCommand("TRUNCATE TABLE " & Tabelnaam, connection)
        QuerVerwijdertabel.ExecuteNonQuery()
    End If
End Sub
于 2012-06-19T00:02:50.083 回答
0

我认为您需要更改 MsgBox 中的代码。我已经测试了如下代码,它工作正常:

Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    LaunchHere(ComboBox1.Text)
    MessageBox.Show("Back into Main ComboBox1_SelectedIndexChanged")
End Sub

Sub LaunchHere(ByVal abc As String)
    Dim response As MsgBoxResult
    response = MsgBox("Hello from inside Launch", MsgBoxStyle.YesNo, "Title")
    If response = MsgBoxResult.Yes Then
        MessageBox.Show("Inside Launch Here and used YES")
    Else
        MessageBox.Show("Inside Launch Here and used NO")
    End If
End Sub
于 2012-06-19T00:04:25.210 回答