Solved

programming msgbox.

Posted on 2006-06-14
8
221 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
z = x + y – 1 6 58
Macro which automatically sends attachment to Outlook 14 52
MsgBox 2 38
Passing a Text Box name to a Sub 6 23
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now