问题
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.
回答1:
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:
- MsgBox Function.
来源:https://stackoverflow.com/questions/50478148/how-do-i-know-the-input-i-get-from-a-msgbox