473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Three way operation, Save on close msg

daniel aristidou
491 256MB
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
9 2138
debasisdas
8,127 Expert 4TB
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
866 512MB
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
8,127 Expert 4TB
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
491 256MB
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
8,127 Expert 4TB
Guys i using vb08 inwhich vbyesnocancel does exist.
your solution worked.
Thanks
Daniel(~_~)
ok, you are most welcome .
Jan 3 '08 #6
Killer42
8,435 Expert 8TB
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
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
Killer42
8,435 Expert 8TB
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
thanks seal6039 for the nicely crafted code.
Mar 4 '08 #10

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

Similar topics

4
by: Andras Gilicz | last post by:
Hi VB fans I'm working on a relatively large project in VB6 with about a dozen forms, including graphs, labels, text boxes, etc. The software itself is actually a flow simulator with more or...
2
by: Mark | last post by:
Hi, I'm running visual studio 2003, and am now receiving the error "The Operation Could Not Be Completed" when attempting to add a form / control or component class to a project. I can add any...
2
by: Alex Wisnoski | last post by:
I have an A97 application that I am modifying. I have created an unbound form, "zfrmTestEnterPlacements", with a subform, "zsfrmSelectPlacement". The intent is to use a combo box on the primary...
4
by: martin | last post by:
Hi, I am copying an xml file like so. Dim xmlDoc As New XmlDocument xmlDoc.Load("C:\Program Files\Templates\message.msg") Console.WriteLine("Tmaplate loaded") xmlDoc.Save("C:\Program...
0
by: Joel | last post by:
Creating an Outlook Add-in with VB.NET to automatically save messages for users. The problem occurs if I create a reference (withevents) to the MailItem Object when a new Inspector object is...
8
by: Jim in Arizona | last post by:
I've been using an example out of a book to be able to edit the rows in a database. I am getting the following error: ========================================================...
0
by: Svein Terje Gaup | last post by:
Hi, I have some code on .NET 2.0 that creates a TransactionScope and then tries to open a SQL Connection. When I try to open the connection, I get this error: Test method...
6
by: thesinnerishere | last post by:
hello! how can the save task be completed when the popup is closed in javascript. for eg i have this save function. so when i click on the OK of confirmation dialog box , the popup should also...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.