xsharp.eu • Using wordbasic in X# / VO application
Page 1 of 1

Using wordbasic in X# / VO application

Posted: Wed Oct 16, 2019 5:40 am
by jonhn
Hello again,
In my VO app I have used Wordbasic to generate some simple reports for the user in a new Word doc.

I would like to provide the same functionality in my X# application when converted, but can't figure out how to include the Wordbasic library in my project, and then reference it.

I found some docs from MS regarding C#, but 2 days trying to figure this out is making me crazy.
https://docs.microsoft.com/en-us/dotnet ... erty-value

Can anyone please list the steps involved in getting Wordbasic into the X# app and using it?
Maybe there is a better / different way...

In VO I declare it in the window class where I want it: PROTECT oWord AS wordbasic
And then simple stuff in the method.
SELF:oWord:=Wordbasic{}
IF !SELF:oWord:fInit
WarningBox{SELF,"Can't start MS-Word!","If Word is installed on this computer try opening it manually and try again."}:show()
RETURN NIL
ENDIF

SELF:oWord:FileNewDefault()
SELF:oWord:AppShow()

...<etc...>

Thanks!
Jonathan

Using wordbasic in X# / VO application

Posted: Wed Oct 16, 2019 6:36 am
by wriedmann
Hi Jonathan,
the MS documentation says there is an assembly Microsoft.Office.Interop.Word.dll - you need to include that and add a "using Microsoft.Office.Interop.Word" on the top of your prg file.
I have that DLL file here (Office 2010):
c:WindowsassemblyGAC_MSILMicrosoft.Office.Interop.Word14.0.0.0__71e9bce111e9429cMicrosoft.Office.Interop.Word.dll
Wolfgang

Using wordbasic in X# / VO application

Posted: Wed Oct 16, 2019 6:38 am
by robert
Jonathan,

- Add a reference to the MsWord type library (see our example that covers Excel : https://www.xsharp.eu/help/example-4-ol ... ation.html )
- add a using statement for word: USING Microsoft.Office.Interop.Word
- create an object of the word application: oWord :=ApplicationClass{}
- don't use oWord:Finit, that is what we did with OleAutomation. If word can't be started you will get a normal .Net exception

Robert

Using wordbasic in X# / VO application

Posted: Wed Oct 16, 2019 9:19 am
by jonhn
Thank you Robert and Wolfgang, very helpful! I have found the other MS dll files that can also be referenced so will try to build those in too!

One more question, if I may:
I have a lot of errors: XS0102: The type 'XXXXXX' already contains a definition for 'XYZ'
BUT, I have only declared these variables in the one place.

What is it I need to find / fix to cure this error?

Using wordbasic in X# / VO application

Posted: Wed Oct 16, 2019 9:20 am
by robert
Jonathan,
Jonathan Neil wrote: One more question, if I may:
I have a lot of errors: XS0102: The type 'XXXXXX' already contains a definition for 'XYZ'
BUT, I have only declared these variables in the one place.

What is it I need to find / fix to cure this error?
Give us more info ?

Robert

Using wordbasic in X# / VO application

Posted: Wed Oct 16, 2019 9:44 am
by jonhn
sorry.
In VO I have declared the variables in the class as INSTANCE or PROTECT, or they are Access/Assign variables.
Not all variables.

Looking at it right now, it looks like in X#, because several classes have been gathered up into .prg files, if each class had an instance of that variable, it was not a problem in VO, but in X# they are visible to each other... I need to go and check if that is the reason.
Thanks again.

Using wordbasic in X# / VO application

Posted: Wed Oct 16, 2019 3:16 pm
by Chris
Hi Jonathan,

Please install the newest X# build (from today!), including the new XIDE and then re-export your code with the new VOXporter, it should take care of this as well (it will remove the INSTANCE variables)