Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display a message box in foxpro?

Status
Not open for further replies.

Niki_S

Programmer
Jun 4, 2021
232
0
0
LK
I have already add my messagebox like this. But I want to do some changes.
Code:
SELECT Absent_xl
IF RECCOUNT()>0

	Mesage=Messagebox("Do you want to print excel report?",32+4,"Message")

	IF Mesage=6
		
		namefile= PUTFILE('Excel File:',"Name_file",'xls')
		IF !EMPTY('namefile')
		COPY TO ('namefile') TYPE xl5
		ENDIF 
		
	ELSE 
	
		Select 'Absent_New'

		report form rptabsentemp.frx To Printer Prompt Nodialog Preview
		
	ENDIF 
	
ENDIF

I want to change this as below.
First I want to display a message as "What kind of report do you want?".
And there should have two options as "excel report" and "normal report".
How can I change "yes,no" options into "excel report,normal report"?

Thank you.
 
Regrettably, the button text values are fixed - they are language specific, not that that helps.

You would need to either change your prompt so that it worked with one of the standard texts - such as you have above - or create
a form of your own with programable buttons, or a radio group and ok, cancel options or something similar.

Code:
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

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Hi Niki,

I don't think this is feasible with the MESSAGEBOX. You may however create your own form (see code below)

Code:
*!*	PUBLIC goForm

goForm = CREATEOBJECT("MyForm")
goForm.Show()

READ EVENTS

CLOSE ALL
CLEAR ALL 

**********

DEFINE CLASS MyForm as Form
	
	Width = 180
	Height = 270
	MinWidth = This.Width
	MinHeight = This.Height
	MaxWidth = This.Width
	MaxHeight = This.Height
	Caption = "Reports"
	AutoCenter = .T.
	ShowTips = .T.
	Themes = .F.
	
	ADD OBJECT opgChoice as OptionGroup WITH ;
		Top = 36, ;
		Left = 39, ;
		ButtonCount = 3, ;
		Value = 1, ;
		AutoSize = .T., ;
		Anchor = 9
		
		PROCEDURE opgChoice.Init()
			FOR i = 1 TO This.ButtonCount
				WITH This.Buttons(i)
					.AutoSize = .T.
					.Caption = ICASE(i = 1, "Report Excel", i = 2, "Report PDF", "Report DOCX")

				ENDWITH 
			ENDFOR 
		ENDPROC 
		
	ADD OBJECT cmdPrint as CommandButton WITH ;
		Top = 132, ;
		Left = 45, ;
		Width = 90, ;
		Height = 24, ;
		Caption = "Print", ;
		Anchor = 9
	
		PROCEDURE cmdPrint.Click()
			LOCAL liPrint as Integer 
			
			liPrint = ThisForm.opgChoice.Value
		
			DO CASE 
				CASE liPrint = 1
					WAIT WINDOW + "Printing Excel report" TIMEOUT 3
				
				CASE liPrint = 2
					WAIT WINDOW + "Printing PDF report" TIMEOUT 3
				
				CASE liPrint = 3
					WAIT WINDOW + "Printing DOCX" TIMEOUT 3
					
				OTHERWISE
					WAIT WINDOW + "You have to choose" TIMEOUT 3

				
			ENDCASE 
			
		ENDPROC 

	PROCEDURE Destroy()
		ThisForm.Release
		CLEAR Events
		
	ENDPROC
ENDDEFINE

hth

MarK
 
You'd need to reach deep into the bag of tricks you can do on Windows. Craig S. Boyd has developed an FLL which you would need to add to the runtimes that enables to set captions of the three standard Messagebox buttons Abort, Retry Ignore.

Just an excerpt of his code highlighting the change of captions (this does not work standalone!)
Code:
SetDlgItemText(wParam, IDABORT, “VFP Rocks!”) && First Button Caption
SetDlgItemText(wParam, IDRETRY, “Always Has”) && Second Button Caption
SetDlgItemText(wParam, IDIGNORE, “Always Will”) && Third Button Caption

Source:
The whole code is in the MODIFY MESSAGEBOX EXAMPLE.

But will you really want another FLL in your runtimes just for this capability to change captions, if you can simply roll your own messagebox?

Also, why solve this with a question dialog at all?
Why don't you simply use an optiongroup on your form to pick from the two options Excel or Foxpro Report? Then you simply know in advance what the user wants clicking on the print button. A user interface that doesn't go through popping up windows is much better in general. The reason to use messageboxes usually is to highlight something extraordinary, like an error is, a warning, or the safety question whether really to close a form without saving, for example, but not the choice of a report type.

Edit: The simplest interface I can think of is split the print button you have into two buttons, one with an excel icon, one with a printer icon to indicate the two choices of excel export creating a file or normal VFP report to a real (or virtual) printer - usually to paper.

If you use foxyPreviewer saving as Excel or other formats also is part of it and the print preview toolbar.

Chriss
 
I was also going to suggest FoxyDialogs. Tom beat me to it. It's an excellent messagebox substitute which is worth everyone considering

But, in this case, I agree with Chris that a messagebox is unnecessary - and even intrusive. You already have a form for launching the report. Just add a control to that form to let the user choose Excel or normal.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
This is my combined Printer selection/Excel/PDF/Preview dialog:

DIALOG_sv6eyr.jpg

Even if texts are in Swedish, I think you get the idea.

What you can't see is if you click on the small printer icon down left you get a regular Message box where Yes=Remove printer info from the report, No=Edit the report and Cancel of course cancels :)
PS. Enter=Default and previews the report. Double-click on a printer directly passes the report to that printer.
PPS. "Öppna PDF" means automatically open the produced PDF in the default program.
"Svart-Vitt" menas print in black and white (regardless of destination).

Also in the title bar where it says "Skriv ut" (Print) and there is a text inside of brackets. That's the exact name of the print job going to the spooler. I accomplish this by copying the original report to %TEMP% and then rename it to a unique name before executing it.
 
Thank you all!
I changed the format and I used radio buttons to select the type. Now I want to know that, how can I display excel sheet with current records when I select "excel option".
Can anyone please tell me how to do that?

Thank you
 
You should start a new thread

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top