By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,883 Members | 2,037 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,883 IT Pros & Developers. It's quick & easy.

Three way operation, Save on close msg

daniel aristidou
100+
P: 491
Hey guys any one know how to make a msg that is vbyesnocancel And do a different command depending on which the user pressed
For example when closing the window ..... have the option of sve and close,close or cancel.

You don't use an if statement do you?

Daniel(~_~)
Jan 3 '08 #1
Share this Question
Share on Google+
9 Replies


debasisdas
Expert 5K+
P: 8,127
Yes you use if for this
try like this

Expand|Select|Wrap|Line Numbers
  1. rep=msgbox("Do you want to save",vbyesnocancel + vbquestion,"Save Data...!")
  2. if rep=vbyes then
  3. 'save the data
  4. elseif rep=vbno then
  5. 'don't save the data
  6. else
  7. 'do nothing
  8. end if
  9.  
Jan 3 '08 #2

lotus18
100+
P: 866
Yes you use if for this
try like this

Expand|Select|Wrap|Line Numbers
  1. rep=msgbox("Do you want to save",vbyesnocancel + vbquestion,"Save Data...!")
  2. if rep=vbyes then
  3. 'save the data
  4. elseif rep=vbno then
  5. 'don't save the data
  6. else
  7. 'do nothing
  8. end if
  9.  
Does this vbYesNoCancel a constant value of message box property? Or am I wrong? All I know is vbRetryCancel . For vbYesNoCancel, we can combine vbYesNo + vbCancel. : )
Jan 3 '08 #3

debasisdas
Expert 5K+
P: 8,127
Does this vbYesNoCancel a constant value of message box property? Or am I wrong? All I know is vbRetryCancel . For vbYesNoCancel, we can combine vbYesNo + vbCancel. : )
i don't remember exactly . I don't have vb 6.0 in my office.

try to use vbYesNo instead.
Jan 3 '08 #4

daniel aristidou
100+
P: 491
i don't remember exactly . I don't have vb 6.0 in my office.

try to use vbYesNo instead.
Guys i using vb08 inwhich vbyesnocancel does exist.
your solution worked.
Thanks
Daniel(~_~)
Jan 3 '08 #5

debasisdas
Expert 5K+
P: 8,127
Guys i using vb08 inwhich vbyesnocancel does exist.
your solution worked.
Thanks
Daniel(~_~)
ok, you are most welcome .
Jan 3 '08 #6

Expert 5K+
P: 8,434
Just one thing. For multiple choices based on a single value like this, I'd recommend using Select Case rather than If.
Jan 4 '08 #7

P: 1
The YesNoCancelMsgBox function shows how to handle vbYes, vbNo, vbCancel and clicking the top right close button. The YesNoCancelMsgBox function below it shows how to call it and use the result as the message string in another message box. The result can also be applied to a string variable in the same way with one line of code instead of having paste all of the code repeatedly. (Integers are better to return but I instead used strings to simplify.)

Expand|Select|Wrap|Line Numbers
  1. Public Function YesNoCancelMsgBox(Message As String, Title As String) As String
  2.     Dim Result As Integer
  3.     Result = MsgBox(Message, vbQuestion + vbYesNoCancel, Title)
  4.  
  5.     Select Case Result
  6.         Case 7
  7.             YesNoCancelMsgBox = "No"
  8.         Case 6
  9.             YesNoCancelMsgBox = "Yes"
  10.         Case 2
  11.             YesNoCancelMsgBox = "Cancel"
  12.         Case Else
  13.             YesNoCancelMsgBox = "Close Button"
  14.     End Select
  15. End Function
  16. Private Sub CallYesNoCancelMsgBox()
  17.     MsgBox YesNoCancelMsgBox("Choose Yes, No, Cancel or the top right Close button.", "Message Box Test..."), vbExclamation + vbOKOnly, "Message Box Test Results"
  18. End Sub
Jan 26 '08 #8

Expert 5K+
P: 8,434
Thanks for that, seal6039. Handy stuff.

I would make a couple of minor suggestions, though.
  • In VB6, it's generally better to use Long rather than Integer, for performance reasons. (Of course performance is unlikely to be an issue in this case, since you are waiting on the user anyway.)
  • I believe it makes for more easily readable code if you use the built-in constants rather than literal values. For example, vbYes rather than 6, and so on.
Jan 27 '08 #9

P: 59
thanks seal6039 for the nicely crafted code.
Mar 4 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.