views:

43

answers:

2

in visual basic in studio if this is used for giving a message

MsgBox("hello", 4, "status")

how to manipulate the result yes or no from the msgbox like this should happen if the user gives no and this should happen if no

+2  A: 

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
SLaks
Why would you write vbYes = MsgBox(...) instead of MsgBox(...) = vbYes? Reformed C programmer?
Jason Berkan
@Jason: No. I write it that way because MessageBox / MsgBox calls get very long, and I don't want to need to scroll to the right to see the comparison.
SLaks
Ah - that makes perfect sense.
Jason Berkan
+1  A: 

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
Leniel Macaferi