开发者

How do I take the result from a message box?

开发者 https://www.devze.com 2023-01-02 05:19 出处:网络
In Visual Basic in Visual Studio 2010, if this is used for giving a message, MsgBox(\"hello\", 4开发者_开发百科, \"status\")

In Visual Basic in Visual Studio 2010, if this is used for giving a message,

MsgBox("hello", 4开发者_开发百科, "status")

how do I manipulate the result Yes or No from the msgbox?

Like this should happen if the user gives No and this should happen if No.


You need to check whether MsgBox returned vbYes.

For example:

If vbYes = MsgBox("hello", vbYesNo, "status") Then
    'Do things
Else
    'Don't do things
End If


MsgBox Function (Visual Basic)

Lesson 10: Introduction to VB Built-in Functions

Sample code:

Private Sub Test_Click()

    Dim testMsg As Integer

    testMsg = MsgBox("Click to test", 1, "Test message")


    If testMsg = 1 Then                    'User clicked on OK button
       Display.Caption = "Test Succeeded"
    Else                                   'User clicked on Cancel button
       Display.Caption = "Test failed"
    End If

End Sub


Pretty sure you can just do this also:

Dim response As MsgBoxResult = MsgBox("Are You Sure you want to delete this entry?", MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.YesNo Or MsgBoxStyle.Critical, "Warning")



 If response = MsgBoxResult.Yes Then
0

精彩评论

暂无评论...
验证码 换一张
取 消