INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Tips -N- Tricks

Messagebox - YESNO by jimoo
Posted: 24 Oct 03 (Edited 2 Apr 04)

* By Jim Osieczonek, www.deltbg.com

#IF .F.
This method was written in 5.0 and I have use it since.  It has been a great FOR using interactively (command window, etc.) AND from a program.  It was best in prior 7.0 era, when the messagebox returned an error if you passed in non-character data.  

It is still a great tool today.  
1. It provides your app with common looking messageboxes.
2. It is whole lot more readable and easier to remember than those cryptic messagebox parameters.
3. Easy to program using it.
   
This one is for YESNO, I'll share a few of my others.  They include STOP() and INFO()    

Notice, the proper ICON is displayed (see footnote at bottom), and the system title is displayed.  If a title is not passed it, it will look for a public memory variable (change it to your needs)
but for this example I'll call it gcSystem.

COPY all this text including comments because the compile will ignore the since they are contained in #IF/END, into a program.  Save the program and execute it.

You'll see how it works.

#ENDIF

PUBLIC  tcSystem
tcSystem = "Tek Tip"
IF YESNO([Are you feeling well]) = [YES]
   MESSAGEBOX([I am happy to hear you are well.],[Tek-Tip])
ELSE
   MESSAGEBOX([I hope you are feeling better soon.],[Tek-Tip])
ENDIF   

* Isn't this a nice easy way to program?

*****************************************************************************
PROCEDURE YESNO
LPARAMETER tcMessage,tcTitle,tnDefaultButton
* syntax:
* lcans = YESNO[Are you happy])
* default is the NO button unless you tell it otherwise with a 2nd parm.

DO CASE
CASE PCOUNT() = 0
    tcMessage = [Duh...   No Message Passed]
    tnDefaultButton = 2
CASE PCOUNT() = 1
    tcTitle = tcSystem
    tnDefaultButton = 2
CASE PCOUNT() = 2
    DO CASE
    CASE TYPE('tcTitle') = [C]
        * they passed in a title but no default button.
        tnDefaultButton = 2
    CASE TYPE('tcTitle') = [N]
        * they passed in a default button, but no title
        IF tcTitle = 1
            tnDefaultButton = 1
        ELSE
            * anything else we'll set to NO
            tnDefaultButton    = 2
        ENDIF    
        tcTitle = tcSystem
    OTHERWISE
        tcTitle = tcSystem
        tcDefaultButton = 2
    ENDCASE
CASE PCOUNT() = 3
    DO CASE
    CASE TYPE('tcTitle') = [C] AND TYPE('tnDefaultButton') = [N]
        * this what is expected.
        IF tnDefaultButton = 1
            * YES
        ELSE
            * only 1 and 2 are valid
            * set all others to 2
            tnDefaultButton = 2
        ENDIF    
    CASE TYPE('tcTitle') = [N] AND TYPE('tnDefaultButton') = [C]
        * let's assume the dumb-dumb (I hope it's not me) passed
        * the parms in backwards.
        
        LOCAL lcTemp
        lcTemp = tnDefaultButton
        tnDefaultButton = tcTitle
        IF tnDefaultButton = 1
            * YES
        ELSE
            * only 1 and 2 are valid
            * anything other 1 we'll set to 2
            tnDefaultButton = 2
        ENDIF
        tcTitle = m.lcTemp
    OTHERWISE
        * we can only do so much.
        tcTitle = tcSystem
        tnDefaultButton = 2
    ENDCASE
ENDCASE

IF tnDefaultButton = 1
    tnDefaultButton = 0
ELSE
    tnDefaultButton = 256
ENDIF    

RETURN IIF(MESSAGEBOX(tcMessage,4 + 32 + tnDefaultButton,m.tcTitle)=6,[YES],[NO])

#IF .F.
Footnote:  This information was provided by Craig Berntson. It originated on MS Developers guidelines:

"...the question mark message icon is no longer recommended, because it does not clearly represent a specific type of message and because the phrasing of a message as a question could apply to any message type. In addition, users can confuse the message symbol question mark with Help information. Therefore, do not use this question mark message symbol in your message boxes. The system continues to support its inclusion only for backward compatibility."


I like to use the question mark in my messagebox when asking a question.  You may wish to change it to fit UI Guidelines if you prefer.

#ENDIF

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close