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

New to Foxpro: Trying to Open Adobe File

Status
Not open for further replies.

bcoats

Programmer
Jun 20, 2001
49
0
0
US
What I am trying to accomplish is to open an adobe file for the selected client so that the user can scan in information or whatever they want to do with this adobe file. What I have is this from poking around on this forum.

Code:
myPath = "\Data\charts\" + str(chart.key) + ".pdf"
myResult = ShellExecute(0, "Open", mypath, "", "", 1)

When I click the button nothing hapens at all. Now I know that the file doesnt exist so that may be why nothing is happening.

I guess I have a few questions.

1. IS this the way to say put the file in the directory under the working directory of the program. Which is where I would like it.

2. Is there something else I have to do to create the folder and or the file. And is so, how do I check to see if the folder / file exist to know if I need to create them before I try to open the file.

3. Any other suggestions or instruction about this sort of thing would be greatly appreciated.

bcoats
 
You may need to specify the drive letter also, since shellexecute doesn't really know or care what your working folder is.
You may also need to add ALLTRIM(str(chart.key)) around your field as it probably has spaces in it.

But start with putting a valid file in the folder before you bother testing.

-Dave Summers-
[cheers]
Even more Fox stuff at:
 
The DIRECTORY() and FILE() functions will help you in determining whether the folder and file already exist, see the FoxPro Help system for exact usage.

Not sure how you'd create an Adobe file from FoxPro. Have you searched these FoxPro forums for help on that already?

hth
dennis
 
Well, that would be ok except I need to create the file as well as open an existing one.

Is there a way to get the path of the programs working directory? That would be great because I am trying to keep the user from having to designate the target directory.

thanks

b
 
Current workig directory is returned by the CURDIR() function.

I did a quick advanced search on these forums for keywork pdf and saw what looked like some threads that describe creating pdf's (at least from FoxPro reports).

dennis
 
OK, I have gotten this far.

When I run the following the file seems to be created and closed. The file name is something like 9999.pdf. Then The Adobe program begins to start up and read this file but it sayd something about file access error and when I got to see if the file is there, it isn't. Very strange to create a file and it not be there... Any suggestions on this?

Code:
myPath = curdir() +"\Data\Charts\" + alltrim(str(chart.key)) + ".pdf"
if ! directory(curdir() + "\Data\Charts") then
	*Code to make directory here, any help here would be appreciated
endif
if ! file(mypath) then	
	myHandle = fcreate(mypath,2)
	myResult = fclose(myHandle)
endif
myValue = ShellExecute(0, "Open", mypath ,"","",1)
 
This is where I am now. The fcreate() command returning -1. file cannot be created. All I am trying to do is create and empty file that adobe can open with the ShellExecute() command. Here is the code I ahve now. Any thoughts would be appreciated.

Code:
myPath = "c:" + curdir() +"Data\Charts\" + alltrim(str(chart.key)) + ".pdf"
if ! directory("c:" + curdir() + "Data\Charts") then
	*Code to make directory here, any help here would be appreciated
endif
doIt = .T.
if ! file(mypath) then
	myHandle = fcreate(mypath,0)
	if myHandle = -1 then
		messagebox("File could not be created.")
		doIt = .F.
	else
		myResult = fclose(myHandle)
	endif
endif
if doIt then
	myValue = ShellExecute(0, "Open", mypath ,"","",1)
endif

bcoats
 
First, change "\Data\Charts\" to "Data\Charts\" because I think you're ending up with too many slashes in the path. At least I did when pasting your code into a test .prg on my machine.

Then I did see the .pdf get created, but of course it is empty and Adobe will give an error on trying to open it.
 
I see you spotted the extra slash problem already.

Next I would trap the value of str(chart.key) and make sure you're getting something useable.
 
I have done that too. And it looks to be ok. The thing I do know is this, When I go manually make a file outside of adobe, say a text file, then rename it so adobe will open it I get the same adobe error as I get when I run this code. So it looks like I need a way to create a blank adobe file pramatically... Any suggestions would be appreciated.

Bcoats
 
Also, I failed to address your earlier question about creating a directory programmatically. MKDIR and RMDIR commands will make and remove directories.

So, I tested :
MKDIR ("c:" + curdir() + "Data\Charts")
and it works.

Might check the adobe threads for what has to go into a file allow adobe to open it as a blank file.

dennis
 
thanks, I had just found the mkdir command myself and got that to working. I will go check around more to see what there is to see. I will be checking back here to though so if anyone happens to know, I would still appreciate any more help on this.

thanks

bcoats
 

Bcoats,

One other point ..... It's always worth checking the value returned from ShellExecute(). If it's less than 32, it is an error number that might (sometimes) tell you what went wrong.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Hi bcoats,

first welcome to foxpro. Make yourself comfortable. Your sample seems easy to start with, but adresses a problem not bound to or caused by foxpro:

Why do you expect a file with nothing in it, only with the correct file extension in it's name, to be usable with the associated application?

The only file types that allow this are ascii text files like .txt, .log, .bat, ...

Even an empty word file has a length of 10 or more kb, depending on the word version.

This is not special to foxpro but to windows and the applications and the file nature of any media file. They all have their headers, signature, whatever you call it, to make up an "empty" file, a container for the real thing.

If you want empty pdf files and want to open them with adobe, I assume you have acrobat pdf writer or something alike. Why else bother to create empty PDFs?

Simply open that pdf writer up, create a new file, save that and use that as your source file for empty pdf blueprints. Store that empty file somewhere and make a new empty file by copying that one to the destination folder with the appropriate name. (COPY FILE command).

Although I understand, your code is just a starter, it's rather unstable and unflexible, as eg curdir() may change during runtime, if your application get's more complex, and you shouldn't rely on it being the folder, where your PRG or EXE file is located. changing directory with CD or SET PATH will change curdir().

Using "C:" + curdir() shows me you haven't read the help, but simply solve a problem you encounter in a pragmatic way.

The vfp help is really helpful, more helpful than for any other language I worked with. So take it as a general advice to really read it. Type "CURDIR" in the command window, mark/select/highlight that and press F1. If/because that keyword is found, it is highlighted in the toc (table of contents) in the left side of the CHM help browser. With a click you're there.

More correct usage of curdir would either be
Code:
"c:"+curdir("C")
if you want the current directory of Drive C:. curdir() does not return "C:" as you should know that yourselve. If you omit that parameter curdir() returns the curdir for the current drive, which unfortunately is "hidden" behind the commands set("default"), sys(5) or fullpath("\") and not curdrive(). Fullpath() should be your choice, if you want the current dir of the current drive:
Code:
fullpath(curdir())

See the explaination of the parameter and see the "see also" section on the help on curdir() pointing to fullpath().

If you want to bind that path to the prgs file location, make use of SYS(16), to be more precise Sys(16,program(-1)).

Most easy would be to use a foxpro table or ini file to configure that path and not hardcode it. Even if you only hardcode the "\Data\charts\" part. Make and keep it flexible, configurable.

Be warned that if pdf file creation is your most important goal, foxpro has few to no native capabilities to create or write to pdfs. You are dependant on third party tools. The easies may be converting other file formats to pdf or installing a printer driver that creates pdf files instead of really printing, then use office automation to create word or excel files with charts and print these out with that printer driver.

Bye, Olaf.
 
thanks olaf. I think My version of foxpro hasn't got the help stuff so I am trying my best using an old copy of the MSDN. I rarely stay with the hardcoded things after Iget the thing working but I have found them easier examples to post in a forum like this since they are generally easy to understand and have fewer things getting in the way.

Actually your idea of making a blank to use as a template is how I finally solved the problem myself. Great minds think alike I guess. Thanks for all the other functions you mentioned. I am going to give those a try.

Bcoats
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top