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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Notepad 2

Status
Not open for further replies.

asm338s

Programmer
Jul 16, 2001
135
US
I am sending a report to a .txt file. After the program creates thie file I want to open this .txt file so the users can see the report generated. Any Ideas? Thanks in advance.
 
If you are doing this within VFP, you can use

MODIFY COMMAND TheReport.TXT NOEDIT

after printing to a text file to just open it for viewing.

Dave S.
 
Yes, but I want to open this file in Notepad or any other text editor so the users can save this file.
I use Report form abc.frx to file abc.txt ascii

abc.txt is a temp file, so I want to allow users to view this file and save it under a different name.
 
Sorry, I misunderstood. Try this:

REPORT FORM abc.frx TO FILE GETFILE() ASCII

See the help file for more parameters for GETFILE().

Dave S.
 
Or, maybe I didn't. You can open the file using MODIFY COMMAND, or rather, MODIFY FILE. The NOEDIT option is up to you but the user can then select File->Save As and save it wherever they want after looking at it.

Dave S.
 
The best way I have found to do this is with the ShellExecute. It is simple to use and will open the text file in whatever program is set in the file association for .txt. Or whatever file type you give it.

I have used this quite a bit and it works great. It may look a little long and drawn out but is actually fairly simple. I usually will try to indicate the original author for this kind of thing but have had this for quite some time and don't remember where I got it exactly. May have been a combination of several places. You can do your error checking on lcCallStat if needed.

_____________________________________________

Procedure execpgm

* WinApi :: ShellExecute
** Function: Opens a file in the application that it's
** associated with.
** Pass: tcFileName - Name of the file to open
** tcWorkdir - Directory where the file is located
** tcOperation - what do you want done with the file? ('Open'
** is usually all you need.)
**
** Return: -1 - You Didn't send me a file name
** 2 - Bad Association (e.g., invalid URL)
** 31 - No application association
** 29 - Failure to load application
** 30 - Application is busy
**
** Values over 32 indicate success
** and return an instance handle for
** the application started (the browser)
** There is no error handling in this Code. This is left to the
** individual programmers.

LPARAMETERS tcFileName,tcWorkDir,tcOperation
LOCAL lcFileName,lcWorkDir,lcOperation, lnCallStat, lcMsgReply
lnCallStat = 0
lnMsgReply = 0

IF EMPTY(tcFileName)
RETURN -1
ENDIF
lcFileName=ALLTRIM(tcFileName)
lcWorkDir=IIF(TYPE("tcWorkDir")="C",ALLTRIM(tcWorkDir),"")
lcOperation=IIF(TYPE("tcOperation")="C" AND NOT EMPTY(tcOperation),ALLTRIM(tcOperation),"Open")

*-* HINSTANCE ShellExecute(hwnd, lpszOp, lpszFile, lpszParams, lpszDir, wShowCmd)
*-*
*-* HWND hwnd - handle of parent window
*-* LPCTSTR lpszOp - address of string for operation to perform
*-* LPCTSTR lpszFile - address of string for filename
*-* LPTSTR lpszParams - address of string for executable-file parameters
*-* LPCTSTR lpszDir - address of string for default directory
*-* INT wShowCmd - whether file is shown when opened
DECLARE INTEGER ShellExecute ;
IN SHELL32.DLL ;
INTEGER nWinHandle,;
STRING cOperation,;
STRING cFileName,;
STRING cParameters,;
STRING cDirectory,;
INTEGER nShowWindow
lcCallStat = ShellExecute(0,lcOperation,lcFilename,"",lcWorkDir,1)

 
Thanks. It worked great. I don't know how to give stars otherwise I'll give you one.
 
Look at the bottom of the post for the person you want to give a star. Click on the link that says "Click here to mark this post as a helpful or expert post!" :eek:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top