Indigo Rose Software
  #1  
Old 02-11-2005
Intrigued's Avatar
Intrigued Intrigued is offline
Indigo Rose Customer
 
Join Date: Dec 2003
Location: Location! Location!
Posts: 6,058
powerBASIC & Word COM automation

This is from a .bas file (Worm) that was apart of a demo from over at the powerBASIC forums:

Code:
'==============================================================================
'
'  oWord.bas example for PowerBASIC Console Compiler
'  Copyright (c) 2002-2004 PowerBASIC, Inc.
'  All Rights Reserved.
'
'  Run a short demonstration of sending data to Microsoft Word 97.
'
'  * Tested with Excel '97 with VBA installed *
'
'==============================================================================


#COMPILE EXE
#DIM ALL
#INCLUDE "oWord.inc"

DECLARE SUB DisplayResult(msg AS STRING)


'------------------------------------------------------------------------------
' Main application entry point...
'
FUNCTION PBMAIN()
    DIM oWordApp  AS WordApplication ' Application Interface
    DIM oWordDoc  AS WordDocument    ' Document Interface
    DIM oWordSel  AS WordSelection   ' Selection

    DIM vBool     AS VARIANT
    DIM vText     AS VARIANT
    DIM vFile     AS VARIANT
    DIM vFileFmt  AS VARIANT
    DIM vVnt      AS VARIANT

    DisplayResult "About to Open MSWORD..."
    ' Open an instance of MSWORD
    SET oWordApp = WordApplication IN "Word.Application"
    IF ISFALSE ISOBJECT(oWordApp) THEN _
        SET oWordApp = NEW WordApplication IN "Word.Application"

    ' Could MSWORD be opened? If not, terminate this app
    IF ISFALSE ISOBJECT(oWordApp) THEN
        DisplayResult "Unable to open or start MSWORD!"
        EXIT FUNCTION
    END IF

    ' Make MSWORD visible
    DisplayResult "About to make MSWORD visible..."
    LET vBool = 1
    OBJECT LET oWordApp.Visible = vBool

    ' Get the current document count from the "documents collection"
    DisplayResult "About to request the MSWORD document count..."
    LET vVnt = 0
    OBJECT GET oWordApp.Documents.Count TO vVnt
    DisplayResult "MSWORD has " & FORMAT$(VARIANT#(vVnt)) & _
        " File(s) loaded!"

    ' Add a document to the "documents collection", and obtain a reference
    ' to the document Interface for the new document
    DisplayResult "Adding a new document to MSWORD..."
    LET vVnt = 0
    OBJECT CALL oWordApp.Documents.Add TO vVnt
    IF OBJRESULT OR ERR THEN
        DisplayResult "MSWORD was not able to start a new document." & $CR & _
            "Please ensure MSWord and VBA are installed."
        GOTO Terminate
    END IF
    SET oWordDoc = vVnt

    ' Get the current document count from the "documents collection"
    ' This should be one value higher than before
    DisplayResult "Checking the MSWORD document count again..."
    LET vVnt = 0
    OBJECT GET oWordApp.Documents.Count TO vVnt
    DisplayResult "MSWORD has " & FORMAT$(VARIANT#(vVnt)) & _
        " File(s) loaded!"

    ' Get the Interface to the currect selection of the document
    DisplayResult "About to obtain an interface to the current selection point..."
    OBJECT GET oWordApp.Selection TO vVnt
    SET oWordSel = vVnt

    ' Enter some text into the document at the selection position
    DisplayResult "..and placing some text at that selection point..."
    LET vText = "PowerBASIC controls Microsoft Word!"
    OBJECT CALL oWordSel.TypeText(vText)

    ' Set a paragraph marker (end of paragraph)
    OBJECT CALL oWordSel.TypeParagraph

    ' Another paragraph
    LET vText = "COM client controls a COM server!"
    OBJECT CALL oWordSel.TypeText(vText)
    OBJECT CALL oWordSel.TypeParagraph

    ' Save the new document to disk
    DisplayResult "About to save the document and close MSWORD..."
    LET vFile    = "Test.doc"
    LET vFileFmt = %wdFormatDocument
    OBJECT CALL oWordDoc.SaveAs(vFile, vFileFmt)

    DisplayResult "All done! The COM automation stuff is pretty cool!"

Terminate:

    ' Close the current document and then close MSWORD completely
    OBJECT CALL oWordApp.ActiveWindow.Close
    OBJECT CALL oWordApp.Quit

    ' Close all of the Interfaces
    SET oWordSel  = NOTHING
    SET oWordDoc  = NOTHING
    SET oWordApp  = NOTHING

END FUNCTION

'------------------------------------------------------------------------------
' Compiler-independent helper function to display feedback and errors
'
SUB DisplayResult(msg AS STRING)
    #IF %DEF(%PB_CC32)
        PRINT msg
        PRINT "Press a key...";
        WAITKEY$
        LOCATE ,1
    #ELSE
        MSGBOX msg, &H00001000& ' %MB_SYSTEMMODAL
    #ENDIF
END SUB
Now, that code did what I have yet to fully achieve, add text too and at a certain position regardless of the version of M.S. Word installed such text in the open document.

I'll have a go soon again on the luaCOM-MSWord situation though.

Without doing my homework yet (d'oh), Worm, what is the .inc file(s) representing? Are they the project files? Or, is the .bas files the (as in base) project file(s)?
__________________
Intrigued
www.amsuser.com
Reply With Quote
  #2  
Old 02-11-2005
Worm Worm is offline
Indigo Rose Customer
 
Join Date: Jul 2002
Location: USA
Posts: 3,937
the inc file is an include file.
It can contain anything from constants, functions, and types, etc.

Think of it as the Global Functions in AMS. Whatever you put in there, becomes available in the project.

I just sent you the inc file via email to look at.
Reply With Quote
  #3  
Old 02-11-2005
Intrigued's Avatar
Intrigued Intrigued is offline
Indigo Rose Customer
 
Join Date: Dec 2003
Location: Location! Location!
Posts: 6,058
Right'O! Thanks.

I'll see how warm I can get my brain tonight... hmmm.. maybe till just a tad of smoke percolates outta' my ears...

__________________
Intrigued
www.amsuser.com

Last edited by Intrigued; 02-11-2005 at 10:24 PM.
Reply With Quote
  #4  
Old 02-11-2005
Intrigued's Avatar
Intrigued Intrigued is offline
Indigo Rose Customer
 
Join Date: Dec 2003
Location: Location! Location!
Posts: 6,058
Did Jeff Foxworthy say this one? (snickering here)

"You might be a Program'Neck, if you are constantly searching Google and find yourself on the 43rd page of results!"


__________________
Intrigued
www.amsuser.com
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
luaCOM and M.S. Word... Intrigued AutoPlay Media Studio 5.0 10 02-09-2005 10:01 AM
opening a word template from AMS Jonas DK AutoPlay Media Studio 5.0 1 01-16-2005 02:21 PM
Opening a Microsoft Word Document Desmond AutoPlay Media Studio 5.0 Examples 0 09-26-2003 02:46 PM
Printing a document with word or notepad hobbsdan AutoPlay Media Studio 4.0 26 05-08-2003 01:01 PM
opening multiple word documents Laurie AutoPlay Menu Studio 3.0 1 06-27-2000 09:25 AM


All times are GMT -6. The time now is 11:21 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software