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.