是/否消息框始终返回yes - VB.Net

Nul*_*ll_ 3 .net vb.net variables msgbox

我正在尝试使用消息框,并尝试了一个简单的是/否消息框所以我编写了这段简单的代码.但是,无论我按什么按钮,"chc"变量总是返回1.我提供了代码,所以你可能会看到我做错了什么.这可能是非常错误的.

If MsgBoxResult.Yes Then
    chc = 1
ElseIf MsgBoxResult.No Then
    chc = 0
End If

MsgBox(chc)
Run Code Online (Sandbox Code Playgroud)

jon*_*ana 5

MsgBox()方法返回MsgboxResult Enumeration,检查该方法返回的值:

Public Sub MsgBoxExample()
    Dim result As MsgBoxResult = Nothing
    Dim chc As Integer

    result = MsgBox("click something...", vbYesNo, "example")
    If result = MsgBoxResult.Yes Then
        chc = 1
    ElseIf result = MsgBoxResult.No Then
        chc = 0
    End If
    MsgBox(chc)
End Sub
Run Code Online (Sandbox Code Playgroud)