messagebox()

2,213 views
Skip to first unread message

migaldra

unread,
Aug 2, 2011, 7:51:46 PM8/2/11
to Comunidad de Visual Foxpro en Español
Estimados
Podrian indicame cuales son los valores que se pueden utilizar para
esta opcion.
Lo que he podido ver es que hay una opcion que permite colocar un
dialogo que indica Si o No, pero no se como hcerlo y ademas si escojo
el SI por ejemplo como sabe el sistema que lo escogui.
Espero me puedan ayudar como siempre.

Luis Mata

unread,
Aug 2, 2011, 7:51:12 PM8/2/11
to Comunidad de Visual Foxpro en Español
de la ayuda de VFP 9 con SP2
 

Displays a user-defined dialog box.

MESSAGEBOX(eMessageText [, nDialogBoxType ][, cTitleBarText][, nTimeout])

Parameters

eMessageText

Specifies the text that appears in the dialog box. You can also specify any valid Visual FoxPro function, object, or data type instead of eMessageText. The maximum amount of text you can specify is 1024 characters.

NoteNote

Visual FoxPro converts object references to the string, "(Object)". If you specify a function that evaluates to a noncharacter value, Visual FoxPro automatically uses the TRANSFORM( ) function to provide the character equivalent. In the following example, a character type date is returned and passed to MESSAGEBOX( ):

CopyCode imageCopy Code
MESSAGEBOX(DATE())
NoteTip

To move a portion of the message to the next line in the dialog box, use a carriage return, CHR(13), in eMessageText. The height and width of the dialog box increases as needed to contain eMessageText.

nDialogBoxType

Specifies the buttons and icons that appear in the dialog box, the default button when the dialog box is displayed, and the behavior of the dialog box.

In the following tables, the dialog box button values 0 to 5 specify the buttons that appear in the dialog box. The icon values 16, 32, 48, and 64 specify the icon that appears in the dialog box. The default values 0, 256, and 512 specify which button in the dialog box is the default button. The default button is selected when the dialog box is displayed. Omitting nDialogBoxType is identical to specifying a value of 0 for nDialogBoxType.

Value Dialog box buttons

0

OK button only

1

OK and Cancel buttons

2

Abort, Retry, and Ignore buttons

3

Yes, No, and Cancel buttons

4

Yes and No buttons

5

Retry and Cancel buttons

Value Icon

16

Stop sign

32

Question mark

48

Exclamation point

64

Information (i) icon

Value Default button

0

First button

256

Second button

512

Third button

nDialogBoxType can be the sum of up to three values, one value from each of the preceding tables. For example, if nDialogBoxType is 290 (2+32+256), the specified dialog box has the following characteristics:

  • Abort, Retry, and Ignore buttons.

  • The message box displays the question mark icon.

  • The second button, Retry, is the default.

Additional information about the constants is available in the FoxPro.h file, located in the Visual FoxPro home directory. Using defined constants such as MB_ABORTRETRYIGNORE + MB_ICONQUESTION + MB_DEFBUTTON2 can be more readable than 2 + 32 + 256.

NoteNote

The question mark 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 could confuse the message symbol question mark with Help Information. Therefore, it is not recommended to use the question mark symbol in your message boxes. The system continues to support inclusion only for backwards compatibility.

cTitleBarText

Specifies the text that appears in the title bar of the dialog box. If you omit cTitleBarText, the title "Microsoft Visual FoxPro" appears in the title bar.

nTimeout

Specifies the number of milliseconds Visual FoxPro displays eMessageText without input from the keyboard or the mouse before clearing eMessageText. You can specify any valid timeout value. A value of less than 1 never times out until user enters input and behaves the same as omitting the nTimeout parameter.

Collapse imageReturn Value

Numeric data type. MESSAGEBOX( ) returns a value that indicates which button was chosen in the dialog box. The following table lists the values MESSAGEBOX( ) returns for each button.

Return value Button

1

OK

2

Cancel

3

Abort

4

Retry

5

Ignore

6

Yes

7

No

In dialog boxes with a Cancel button, pressing ESC to exit the dialog box returns the same value (2) as choosing Cancel.

MESSAGEBOX( ) returns a value of -1 when a timeout occurs.

Collapse imageRemarks

The shortest abbreviation for MESSAGEBOX( ) is MESSAGEB( ).

The MESSAGEBOX( ) function uses smart parameters in that the parameter type determines which parameter is used. The first parameter is required and is always eMessageText. However, the optional second parameter can be nDialogBoxType if the type is Numeric or cTitleBarText if type is Character. The nTimeout parameter is always assumed for the second optional numeric parameter passed. Valid examples include:

CopyCode imageCopy Code
MESSAGEBOX("HELLO","MyTitle",68,6000)

MESSAGEBOX("HELLO",68,"MyTitle",6000)

MESSAGEBOX("HELLO",68,6000)

MESSAGEBOX("HELLO",68,6000,"MyTitle")

Collapse imageExample

The following example displays a user-defined dialog box. The message "Record not found. Would you like to search again?" is displayed as the caption in the user-defined dialog box, and "My Application" is displayed in the title bar.

The user-defined dialog box contains Yes and No buttons and the question mark icon, and the second button (No) is the default button. When you choose one of the buttons, your choice is displayed.

CopyCode imageCopy Code
eMessageTitle = 'My Application'

eMessageText = 'Record not found. Would you like to search again?'

nDialogType = 4 + 16 + 256

*  4 = Yes and No buttons

*  16 = Stop sign icon

*  256 = Second button is default



nAnswer = MESSAGEBOX(eMessageText, nDialogType, eMessageTitle)



DO CASE

   CASE nAnswer = 6

      WAIT WINDOW 'You chose Yes'

   CASE nAnswer = 7

      WAIT WINDOW 'You chose No'

ENDCASE

Collapse imageSee Also

 
 
-----Mensaje original-----
From: migaldra
Sent: Tuesday, August 02, 2011 6:51 PM
To: Comunidad de Visual Foxpro en Español
Subject: [vfp] messagebox()

note.gif
copycode.gif
collapse_all.gif

Darío Castillejos

unread,
Aug 2, 2011, 8:09:58 PM8/2/11
to publice...@googlegroups.com

 

Te recomiendo que leas la ayuda de la función MESSAGEBOX( ) para que veas los valores que retorna y los parámetros que recibe.

Para saber que opción se seleccionó lo evalúas con un IF, ejm:

 

IF MESSAGEBOX(“¿Esta seguro que desea continuar?”, 4+32, “Confirmación”) = 6

         ? “Presionó botón SI”

ELSE

         ? “Presionó botón NO”

ENDIF

 

Los valores devueltos en este mensaje pueden ser:

6 – Significa que presiono SI

7 – Significa que presiono NO

 

 

Saludos.

 

 

 

 

-----Mensaje original-----
De: publice...@googlegroups.com [mailto:publice...@googlegroups.com] En nombre de migaldra
Enviado el: martes, 02 de agosto de 2011 06:52 p.m.
Para: Comunidad de Visual Foxpro en Español
Asunto: [vfp] messagebox()

rfsalasb

unread,
Aug 2, 2011, 9:11:25 PM8/2/11
to publicesvfoxpro
Migaldra, en la ayuda de VFP se explican todos los parámetros, sin embargo te doy unos cuentos para que los chequees:

messagebox("Este será el mensaje principal",32+4+256,"Esto es lo que va en el titulo de la ventana")

los números cambian segun lo que quieres establecer en el mensaje, ejm. 32 = ? 48 = ! 64 = I (Signo de información)
El 4 será los botones a presentar, en este caso: Sí - No.
El 256 indica que por default quedará el focus en el botón de No (por lo menos en este ejemplo).

Algunos programadores utilizan la suma para estas representaciones, es cuestión de gusto, en este caso, sería sustituir 32+4+256 por 292.

Cómo, te dijimos en la ayuda están todos los valores, incluso el como conocer cual es el valor que devuelve según el botón que se haya elegido.
Muchos éxitos.
Saludos.
------------------
rfsalasb
2011-08-02

-------------------------------------------------------------
Remitente:migaldra
Fecha:2011-08-02 17:52:04
Destinatario:Comunidad_de_Visual_Foxpro_en_Español
CC:
Asunto:[vfp] messagebox()

Oscar Calderon Fuentes

unread,
Aug 2, 2011, 9:43:30 PM8/2/11
to publice...@googlegroups.com
revisa la ayuda de VFP al respecto, es más que clara.
--
Oscar Calderón Fuentes
Santiago - Chile
 

Victor Espina

unread,
Aug 3, 2011, 7:10:01 AM8/3/11
to publice...@googlegroups.com
Tambien es recomendable usar las constantes definidas en el archivo FOXPRO.H y no los valores directos, para mejorar la legibilidad. Asi, en lugar de escribir:

IF MessageBox("Desea descartar los cambios?", 4 + 32) = 6
 RETURN ...
ENDIF

es nejor escribir:

#INCLUDE foxpro.h
IF MessageBox("Desea descartar los cambios?", MB_YESNO + MB_ICONQUESTION) = IDYES
 RETURN ...
ENDIF


Ahora, AUN mejor seria que encapsularas las llamadas a MEssageBox en un PROCEDURE personalizado, por ejemplo:

PROCEDURE Mensaje(pcTexto, pnOpciones)
 #INCLUDE foxpro.h
 RETURN MessageBox(pcTexto, pnOpciones)
ENDPROC

IF Mensaje("Desea descartar los cambios?", MB_YESNO + MB_ICONQUESTION) = IDYES
 RETURN ...
ENDIF

Esto te da la gran ventaja de cualquier cambio o mejor que incluyas en MENSAJE() afectaran a toda tu aplicacion, en lugar de tener que buscar todas las referencias a MessageBox() y hacer el cambio una por una. Por ejemplo, si quisieras ahora incluir un titiulo en todos los mensajes de tu aplicacion, lo podrias hacer facilmente modificando Mensaje():

PROCEDURE Mensaje(pcTexto, pnOpciones)
 #INCLUDE foxpro.h
 RETURN MessageBox(pcTexto, pnOpciones, "Mi aplicacion")
ENDPROC

Finalmente, lo realmente ideal seria tener una clase dedicada al manejo de los mensajes en pantalla, usando un metodo generico y luego metodos especializados que hagan uso de ese metodo generico, por ejemplo:

DEFINE CLASS msgHelper AS Custom
 *
 PROCEDURE Mensaje(pcTexto, pnOpciones)
 #INCLUDE foxpro.h
 RETURN MessageBox(pcTexto, pnOpciones, "Mi aplicacion")
ENDPROC

 PROCEDURE Confirmar(pcTexto)
  RETURN (THIS.Mensaje(pcTexto, MB_YESNO + MB_ICONQUESTION) = IDYES) 
 ENDPROC

 PROCEDURE Alerta(pcTexto)
  THIS.Mensaje(pcTexto, MB_OK + MB_ICONEXCLAMATION)
 ENDPROC

 PROCEDURE Error(poEx)
  THIS.Mensaje(poEx.Message, MB_OK + MB_ICONSTOP)
  QUIT
 ENDPROC

 *
ENDDEFINE

Luego, en el inicio de tu aplicacion haces:

PUBLIC msgHelper
msgHelper = CREATEOBJECT("msgHelper")

y luego, por ejemplo, para confirmar una accion:

IF msgHelper.Confirmar("Desea descartar los cambios?")
 RETURN
ENDIF

o para reportar un error:

TRY
  *-- Codigo a validar
CATCH TO ex
 msgHelper.Error(ex)
ENDTRY


El archivo foxpro.h lo consigues en la carpeta principal de VFP y lo que haces es copiarlo a tu proyecto para usarlo.

Saludos

Victor Espina

migaldra

unread,
Aug 3, 2011, 10:13:51 AM8/3/11
to Comunidad de Visual Foxpro en Español
Muchas Gracias por el apoyo, como siempre
saludos


On 2 ago, 20:43, Oscar Calderon Fuentes <ocalder...@gmail.com> wrote:
> revisa la ayuda de VFP al respecto, es más que clara.
>
> El 2 de agosto de 2011 19:51, migaldra <miguelgalv...@gmail.com> escribió:
>
> > Estimados
> > Podrian indicame cuales son los valores que se pueden utilizar para
> > esta opcion.
> >  Lo que he podido ver es que hay una opcion que permite  colocar un
> > dialogo que indica  Si o No, pero no se como hcerlo y ademas si escojo
> > el SI por ejemplo como sabe el sistema que lo escogui.
> > Espero me puedan ayudar como siempre.
>
> --
> *Oscar Calderón Fuentes*
> *Santiago - Chile*
Reply all
Reply to author
Forward
0 new messages