Yes/No message box always returns yes - VB.Net

后端 未结 2 469
陌清茗
陌清茗 2021-01-20 19:47

I was experimenting with message boxes, and tried a simple yes/no messagebox So I wrote this simple piece of code. However, the \"chc\" variable always returns as 1, no matt

2条回答
  •  执笔经年
    2021-01-20 19:57

    The MsgBox() method is returning MsgboxResult Enumeration, check the value that the method returns:

    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
    

提交回复
热议问题