callum
callum

Reputation: 23

How do I know the input I get from a MsgBox?

In VB6 I am trying to find out how to get the input from the user in a MsgBox

Here is my code:

Dim myAnswer As Integer

myAnswer = MsgBox("Do you want to buy this upgrade?", vbOKCancel, "Upgrade Description")

The MsgBox comes up with an ok and cancel button but I don't know how to tell whether or not they clicked ok or cancel.

Upvotes: 2

Views: 141

Answers (1)

41686d6564
41686d6564

Reputation: 19651

Here:

Dim myAnswer As Integer
myAnswer = MsgBox("Do you want to buy this upgrade?", vbOKCancel, "Upgrade Description")

If myAnswer = vbOK Then
    MsgBox "You clicked 'OK'."
ElseIf myAnswer = vbCancel Then
    MsgBox "You clicked 'Cancel'."
' ...
End If

There are 7 constants for the result returned by a MsgBox function:

Constant    Value   Description
vbOK        1       OK
vbCancel    2       Cancel
vbAbort     3       Abort
vbRetry     4       Retry
vbIgnore    5       Ignore
vbYes       6       Yes
vbNo        7       No

References:

Upvotes: 6

Related Questions