Solved

programming msgbox.

Posted on 2006-06-14
8
224 Views
Last Modified: 2010-04-07
How can I program YES, NO and CANCEL button on msgbox statement.

I want the msgbox statement to pop up when user presses delete(a button on my form)..the pop up screen should have three buttons, YES, NO and CANCEL..different codes should be executed be each one..

Thank you.
0
Comment
Question by:Aiysha
  • 4
  • 2
  • 2
8 Comments
 
LVL 8

Accepted Solution

by:
List244 earned 500 total points
ID: 16905452
Dim Result As Integer
Result = MsgBox("MESSAGE", vbYesNoCancel, "TITLE")
If Result = vbYes Then
    MsgBox "Yes"
Else
If Result = vbNo Then
    MsgBox "No"
Else
If Result = vbCancel Then
    MsgBox "Cancel"
End If
End If
End If
0
 
LVL 8

Expert Comment

by:List244
ID: 16905457
Then where I put : MsgBox "Yes" MsgBox "No" and MsgBox "Cancel" you would of course erase that and put the code you want
to take action in those areas.
0
 
LVL 8

Expert Comment

by:List244
ID: 16905471
Another approach would be using a select statement:

Select Case MsgBox("MESSAGE", vbYesNoCancel, "TITLE")
    Case vbYes
        MsgBox "Yes"
    Case vbNo
        MsgBox "No"
    Case vbCancel
        MsgBox "Cancel"
End Select
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16905488
Dim ret As Long
ret = MsgBox("are you sure you want to delete this file", vbYesNoCancel, "sure?")
If ret = vbYes Then
   'user clicked Yes
ElseIf ret = vbNo Then
   'user clicked no
ElseIf ret = vbCancel Then
   'user clicked cancel
End If

0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16905496

List244 you beat me to it ;)

i had to press f5 before submitting :(
0
 
LVL 10

Expert Comment

by:fostejo
ID: 16906283
Aiysha,

You might also want to have a look at MZ-Tools 3.0 freeware available at http://www.mztools.com/v3/mztools3.htm

This add in to VB6 has a nice 'MsgBox Assistant' which allows you to 'pick and choose' the combination of buttons, icons and other settings you want. You can then preview it to make sure all's ok, prior to generating the required code to support the MsgBox.

(Plus it's got a load of other useful features also, such as Code Review, templates etc.)

cheers,
0
 
LVL 8

Expert Comment

by:List244
ID: 16906324
Aiysha, with all honesty, I do not believe you should go about using that, at least not for message boxes.  Tools that help us
get things done are great.  But message boxes are so simple that you would in my opinion cause yourself nothing but harm
by using such a tool.  It creates a tendency to be lazy much like copy-pasting.  I believe as a beginner to a language you should
practice as much as you can to learn what you can do.  As a beginner taking shortcuts is really not the way to go.  After you
learn and understand concepts, if you are trying to get something done, that is when you should use shortcuts, yet even then
do so carefully.
0
 
LVL 10

Expert Comment

by:fostejo
ID: 16907285
Aiysha,

Although I posted the comment, I do also agree with List244 !!

However, in my defence ;), tools like that 'create' some well structured and working code and allow you to explore the various options available to you that you might have never otherwise considered or 'bumped into' - in this instance, you can 'preview' what's going to the created and then pick apart *how* it does what it does from the code itself.

cheers!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question