Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

vbYesNo Message Box

Hi All,

A very simple question, I have a msgbox which gives a user the option to save file to Floppy Disk YES or NO.

MsgBox "Please insert Floppy Disk:?", vbYesNo, "Export"
FileCopy "d:\tmp\Test1.txt", "a:\data_" & Format(Now, "yyyy-mm-dd HhNn") & ".txt"

From the above code it would copy the file even if the user selected the option NO.

Not sure how to write a loop, i.e :confused: .

if vbYesNo = Yes then
FileCopy "d:\tmp\Test1.txt", "a:\data_" & Format(Now, "yyyy-mm-dd HhNn")
end if
[547 byte] By [mp_direct] at [2007-11-11 7:13:07]
# 1 Re: vbYesNo Message Box
Look up the MsgBox function in VB's online help. At the top of the Help topic, there's a link labeled "Example."
Phil Weber at 2007-11-11 17:27:18 >
# 2 Re: vbYesNo Message Box
Hi try this
I was just working on a message box so I still had the code fresh in my mind :)

hope that helps

Drew

Dim Example As Integer
Example = MsgBox "Please insert Floppy Disk:?", vbYesNo, "Export")

If Example = VbYes Then
FileCopy "d:\tmp\Test1.txt", "a:\data_" & Format(Now, "yyyy-mm-dd HhNn") & ".txt"
end if

If Example = VBNo Then
' what ever you want to do with a no reponse
End If
Drew_gable at 2007-11-11 17:28:19 >
# 3 Re: vbYesNo Message Box
The only way I would change Drew's example is to declare the Example variable as VbMsgBoxResult rather than Integer (and give it a more meaningful name ;-):

Dim Response As VbMsgBoxResult
Response = MsgBox ...

If Response = vbYes...
Phil Weber at 2007-11-11 17:29:16 >
# 4 Re: vbYesNo Message Box
'Try this...

Dim Answer as integer
Answer=Msgbox("Your prompt",vbyesno,"Your title")

'if Answer = 6
'then
'Answer = vbyes

'if Answer = 7
'then
'Answer = vbno

.
sarun101 at 2007-11-11 17:30:22 >
# 5 Re: vbYesNo Message Box
Or simply ...

If MsgBox ("Please insert Floppy Disk:?", vbYesNo + vbQuestion, "Export") = VbYes Then
FileCopy "d:\tmp\Test1.txt", "a:\data_" & Format(Now, "yyyy-mm-dd HhNn") & ".txt"
Else
'The user selected 'No'
End If

Note the '+ vbQuestion' - this gives a 'big' question mark on your message box.

With Drew's example, the 'If Then' for 'Yes' should have an 'Else' instead of another 'If' following the first one ... ;-)
gupex at 2007-11-11 17:31:28 >