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

Opening a word document 2

Status
Not open for further replies.

CleoMan

Programmer
Jun 18, 2003
110
ZA
Now for another problem:

How do I go about opening and printing a Word document from within Paradox 9?

General suggestions as to where to start looking for help will be greatly appreciated, thanks

Richard
 
The execute command including a command-line argument containing the path and name of the document file should get it open. If Word has a 'Print' command-line option, that would do it, otherwise you need to explore the DDE functions in Paradox, which allows remote control of other programs.

Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 


"The execute command including a command-line argument containing the path and name of the document file should get it open"

I am sorry but i could not get this to work, I could open Word but not the specific document

The document is called HolderAdmission and is located in c:\My Documents

So could someone please show me a execute example to open the document

Thanks in advance

Richard
 
Try looking at it this way - Note that the quotes must be part of the command line string if the path or file name has a space in it (use a preceding slash for each):

Code:
var
 myString
endVar

myString = "C:\\Program Files\\Microsoft Office\\OFFICE11\\winword.exe "
+
"\"C:\\My Documents\\Holder Admission.doc\"" ; argument

view(myString) ; see the entire command line statement

execute(myString) ; make it go


The path to the Word executable may be different on your PC.



Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Richard,

Here's a way to do this that doesn't hardcode the path to Word. It'll basically open your document using the application registered to .DOC files:

Code:
uses "Shell32.dll"
   ShellExecuteA( hWnd CLONG, lpOperation CPTR,
                  lpFile CPTR, lpParams CPTR,
                  lpDirectory CPTR, nShowCmd CWORD ) CLONG
endUses

method pushButton(var eventInfo Event)
var
   strDir,
   strDoc    String
   liRetVal  longInt
endVar

   strDir = "c:\\docume~1\\username\\mydocu~1\\"
   strDoc = "holder~1.doc"
   if not isFile( strDir + strDoc ) then
      msgStop( "Can't Open File", "Reason: Can't find a file named " +
               strDir + strDoc + "\"; please check the name." )
   else
      ShellExecuteA( 0, "open", strDoc, "", strDir, 0 )
   endIf

endMethod

Now, you'll notice that this is slightly different than the usual code I've posted. As you review it, keep the following points in mind:

1. The Uses...EndUses block declares a prototype of a Windows API call; that is, it tells Paradox about a function from Windows itself and how to call it from the Shell32.dll.

2. You'll notice that I converted the long filenames to their 8.3 equivelants. This may be necessary, but it may also work using the long filename versions. Try the short filenames if you have troubles getting the long filenames to work.

3. When specifying filename backslashes in ObjectPAL, don't forget to use two backslashes, as shown above. Backslash is a the ObjectPAL escaping character, so you need to use two to prevent the interpreter from trying to parse escape characters in your string.

4. Note that while the API function is called ShellExecute, we called a function called shellExecuteA. Windows actually provides two ShellExecute functions: one for ANSI characters and one for Unicode (Wide) characters. Most users will want the A version. If you're using Kanji or a similar character set, call ShellExecuteW instead.

5. To determine if shellExecute ran sucessfully, check the return value. If it's greater than 32, that indicates the window handle of Word (which means it ran successfully). If it's less than 32, that's an error condition (usually file Not Found).

6. You may need to adjust the username portion the value assigned to strDir. Basically, this needs to be set to the directory containing your document.

Hope this helps...

-- Lance

P.S. If you want to print the document, change "open" to "print". This will launch Word, open your document, dump it to the printer, and then exit Word.
 
Thanks lance , the code you gave worked perfectely!
 
Nearly a year after this was posted, I used the code provided by Lance to open a PowerPoint file. By substituting "show" for "open" in the ShellExecuteA command the file would open in the slide show mode. And when Esc was hit to exit slide show mode, PowerPoint would close also, and I would be back to my Paradox form.

One thing I can't explain is that if I used "open" I had to execute the ShellExecuteA command twice (either by pushing the button I created twice or by putting two ShellExecuteA statements into the method). On the first execution, there would be a brief display of the PowerPoint (2002) startup screen, but the file itself would not open. Does anyone know why? Using "show" I only had to execute the command once.

I created a table to store the directory and file names so the button will open the correct PowerPoint file for each linked record. And I didn't have to deal with the double \\ that way. I had no problem with the long file names - and the PowerPoint files were stored on a server directory. Running Windows 2000, Paradox 10 (and Runtime 10).

Works Great!
 
right click on the file and choose open?

oh, never mind.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top