我最近遇到了一个问题,如果我用msgbox.styleyesno调用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
问题是,在子Tabel_Leegmaken结束后,它不会返回到“Private Sub cmbLeegmaken_SelectedIndexChanged”。
我不知道它是否与msgbox在那里被调用有什么关系,但我似乎无法让它工作(即使它可能是一些小错误,我似乎无法看到发现><)。
提前致谢!
答案 0 :(得分: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
答案 1 :(得分: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