hi,
i have the following code to shut down the computer but when i click on no it still shuts down the computer
msgbox "do you want to shut down the computer", vbYesNo
if vbYes then
CODE TO SHUT DOWN COMPUTER
end if
please help
Merlin ?
Printable View
hi,
i have the following code to shut down the computer but when i click on no it still shuts down the computer
msgbox "do you want to shut down the computer", vbYesNo
if vbYes then
CODE TO SHUT DOWN COMPUTER
end if
please help
Merlin ?
You are not "reading" the result from the MsgBox. Change it to this
if vbYes = msgbox ("do you want to shut down the computer", vbYesNo) Then
CODE TO SHUT DOWN COMPUTER
end if
needs to be like this:
Code:
If (MsgBox("do you want to shut down the computer", vbYesNo) = vbYes) Then
'' Code to shutdown
End If
Thanks Guys !!
While the above two examples are correct, i think it is a good idea of getting into the habit of placing the reult into a variable.
This will let you test diferetent values that are returned when you move onto more than two buttons.
Code:Dim lResult As Long
lResult = MsgBox ("Shut Down ?", vbYesNo)
If lResult = vbYes THen
'shut down
End If
Just so you're clear:
MsgBox is a function, it returns a result (an integer) which relates to the button the user clicked or pressed. Therefore you have to evaluate the return value from the function and execute code accordingly.
vbYes
vbNo
vbCancel
etc. etc.