Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word.basic Help for older application
Message
De
24/09/2003 06:39:14
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00831272
Message ID:
00831768
Vues:
17
>Thanks Cetin I'll have a look at this. What I'm trying to decipher is pretty simple stuff. Very few commands even have parameters and never more than one. Just figuring out that oWord.DocClose(2) means 'close without saving' was a big AhHa!
>
>Everything still works as compiled in 1997 except on the machine that uses Word from Office XP where a strange font substitution is taking place. It seems odd because all workstations print to the same printer and this is the only one with problems. I don't know much about XP but I guess I'm about to learn. It's ironic, and probably not a coincidence, that the oldest software and the newest worstation OS are involved in the problem.

Hmm I'd take a step to convert word.basic commands to word.application commands :)
While it does sound hard to do at first it's not because word.application exposes word.basic commands through its 'basic' object. IOW you can mix word.application commands with word.basic commands. It looks like :

oWord = CreateObject('word.application')
oWord.Documents.Add
or with basic :
oWord.Basic.FileNewDefault

Code shows better :)
*!* This example inserts first 10 recs from employee table
*!* Bookmarks each as inserted
*!* Moves odd recno() records to eof
*!* Please notice that this is for word97
*!* Word.basic commands work unchanged in word95 & word97 (Those used here)
*!* Some sections are commented to show the same syntax (or alternative)
*!* for VB and wordbasic

#Define NL Chr(13)
Public oWordDocument

*** set the LOCALEID to English
nlLocaleId=Sys(3004)	&& Save local id
=Sys(3006,1033)		&& We will be sending instructions in English
Use employee	&& test table
Wait Window Nowait "Creating Word Document..."

oWordDocument=Createobject("word.application")	&& Create word object
With oWordDocument.wordbasic
  .appshow			&& Show word app
  .filenewdefault       	&& New file, default template
  Scan While Recno() <= 8
    .formatfont(12,,6)		&& 12 points, red
    .editbookmark("b"+Alltrim(employee.emp_id),,1) && Add bookmark as emp_id
    * oWordDocument.activedocument.bookmarks.add(cBookmark) - VB syntax
    .Insert(Ltrim(Str(Recno()))+"-"+Trim(employee.last_name)+;
      ","+employee.first_name+NL)
    * Insert employee name - recno is just for us to track
    .formatfont(10,,5)				&& 10 points, Magenta
    .Insert(employee.notes+NL+NL)  		&& Insert employee notes
    * Insert odd recs as selstart, even as selend into an array
    If Recno()%2 = 1
      Dimension aBookMarksRange[;
          iif(type("aBookMarksRange")="U",1,;
          alen(aBookMarksRange,1)+1),2]
    Endif
    Store "b"+Alltrim(employee.emp_id) To ;
      ("aBookMarksRange[alen(aBookMarksRange,1),"+;
         Iif(Recno()%2=1,"1","2")+"]")
  Endscan
Endwith
If Type("aBookMarksRange")#"U"	     && Make sure bookmark array exist
  With oWordDocument.ActiveDocument  && Use VB syntax instead of wordbasic
    For ix=1 To Alen(aBookMarksRange,1)
      If .Bookmarks.Exists(aBookMarksRange[ix,1]) ;
          and .Bookmarks.Exists(aBookMarksRange[ix,2]) && Are both defined ?

        .Range(.Bookmarks(aBookMarksRange[ix,1]).Range.Start, ;
          .Bookmarks(aBookMarksRange[ix,2]).Range.End).cut && cut range
        *!*	.Range(.Bookmarks(aBookMarksRange[ix,1]).Range.Start, ;
        *!*  .Bookmarks(aBookMarksRange[ix,2]).Range.End).select && Select range
        *!*	oWordDocument.Selection.Cut		&& Cut selection
        oWordDocument.Selection.Goto(-1,,,"\EndOfDoc")	&& VB goto bookmark
        oWordDocument.Selection.Paste
        * Same word.basic way to cut and paste
        *!*  oWordDocument.wordbasic.editcut       && Wordbasic cut method
        *!*  oWordDocument.wordbasic.endofdocument && Wordbasic goto eod
        *!*  oWordDocument.wordbasic.editpaste     && Wordbasic paste method
      Endif
    Endfor
  Endwith
Endif
Wait Clear
**** Set the LocaleId to the previous value
=Sys(3006,Val(nlLocaleId))
PS: Though basic commands < g > shown in sample work in new object model behavior of some of commands have changed. Use New syntax wheneever possible. Help file has 'Visual Basic Equivalents for WordBasic Commands' entry.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform