Basic

Creating a macro - Writing a Script - Using the API

Basic

Postby Nxx » Thu Dec 13, 2007 1:28 pm

Hi I have two questions about Basic.

First, is it possible to directly run Basic without running the Calc or Writer or another application? Are there any command-line switches for it or so? Is it possible to associate .bas extention with OOo Basic?

Second, is it possible to compile a program with OOo Basic to create a stand-alone application or JRE applet?
Nxx
 
Posts: 10
Joined: Thu Dec 13, 2007 1:22 pm

Re: Basic

Postby DrewJensen » Fri Dec 14, 2007 1:25 am

Frist - yes, you can create a basic library and run any sub procedure or function from this library directly.
For example :

Start OpenOffice.org, any document type or none
Select Tools > Macros > Organize Dialogs
On the dialog that opens select the 'Organize' tab.
Click the button NEW
Give the new library a name ( Library1 is the default )
Click on the button Edit

This opens the Basic IDE with a default sub procedure Main.

Enter something like:
msgbox "Hello World"

Save the file and exit openoffice.org completely.

You can run this new basic sub procedure directly from a command line as
soffice "macro:///library1.module1.main"

The macro will execute and afterwards OpenOffice.org will end.

Second - NO.
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Basic

Postby Nxx » Fri Dec 14, 2007 2:08 am

Is it possible to start the Basic IDE directly into edit mode? Is it possible to start it into a state ready to create a new project without starting other apps?
Nxx
 
Posts: 10
Joined: Thu Dec 13, 2007 1:22 pm

Re: Basic

Postby DrewJensen » Fri Dec 14, 2007 2:16 am

hmmm- never tried that. I imagine you could, but not sure exactly how.

Let me ask you why? When you run a OOBasic procedure like this you are fist loading the entire OpenOffice.org supporting files in memory - not very light by any stretch of the imagination.


If you are looking to create stand alone programs that can work with OpenOffice.org documents then I would suggest maybe looking at the odftoolkit instead. You can not create the programs in Basic however. C++ or Java or maybe Pyhton ( not sure on that last one ) are your choices.

Anyway - maybe a hint as to what you are wanting to build and others might have some other ideas for you.
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Basic

Postby Villeroy » Fri Dec 14, 2007 10:57 pm

This office ships with it's own Python interpreter and many useful libraries. It is a special build prepared to connect to the office and export macros, but you can run it just like any other Python. Although this is a rather old version of Python it is far superior to crappy old Basic.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26401
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Basic

Postby Nxx » Fri Dec 14, 2007 11:39 pm

I did not ask about Python. There are many languages. One can use C or Java or somewhat else. I asked about Basic. The Basic from OOo.
Nxx
 
Posts: 10
Joined: Thu Dec 13, 2007 1:22 pm

Re: Basic

Postby DrewJensen » Sat Dec 15, 2007 12:09 am

There is one advantage to 'crappy old Basic' as our friend there put it, in OOo - the IDE. Granted it isn't the most modern but it is the one built in to the application.

If you want to see how to open the Basic IDE from a script I would start by looking at the Developers Guide - you can find an on-line copy of that at the openOffice.org main web site - Under the api or framework project...arrrgh...let me go see..OK it is the api group
http://api.openoffice.org/DevelopersGui ... Guide.html

That is quite a big document but what you need is in there - I have not seen a break down on how one would do what you ask in the forums...sorry. I don't remember seeing anything in Andrew Pitonyak's Basic Document either - but then I wasn't particularly looking so you might want to check that out also
http://www.pitonyak.org/oo.php

If you find some thing in either of those sources and need clarification by all means ask...
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Basic

Postby Nxx » Sat Dec 15, 2007 11:10 am

How differs for example Calc starter from Writer starter? Both call soffice.bin but differently. It seems that probably Basic was also planned to be an application: soffice even has icon for Basic. Why it was not done? I think because MS did not make VBA stand-alone. But when you close Excel, VBA also closes, though when you close Calc, OOo Basic does not close.

By the way. MS discontinued its VB language. It switched to VB.NET which is very different. There is a substantial community of developers for VB6 who did not switch to VB.NET. There were petitions from devs and users to MS to continue development of VB6, although unsuccessful. I read that OOo Basic is fully compatible with VB both in language itself and built-in libruaries (with exception of SOffice-specific APIs). So it is suitable to create an open-source replacement for VB.
Nxx
 
Posts: 10
Joined: Thu Dec 13, 2007 1:22 pm

Re: Basic

Postby DrewJensen » Sat Dec 15, 2007 12:30 pm

well, not sure where you read that at. VBA and OOoBasic are very different - more so then even VBA and VB6 different from each other.

I suppose you could look at OpenOffice.org like one big widget set..there is a something to be said for that actually. Still though you have to think of OOoBasic as being similar to VBA, not VB6 - similar, not the same.
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Basic

Postby Villeroy » Sat Dec 15, 2007 1:41 pm

Nxx wrote:I did not ask about Python. There are many languages. One can use C or Java or somewhat else. I asked about Basic. The Basic from OOo.

I don't believe that anybody will ever write a cross-platform Basic environment to be shipped with OOo. Basic is dead. StarBasic is a far cry from the 90s when StarOffice was developed by a company named "Star Devision". It is still the easiest way to put a spell on the office. But it is slow, leaking memory, buggy and strictly procedural. This is why I mentioned Python as one alternative.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26401
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Basic

Postby Nxx » Sat Dec 15, 2007 3:12 pm

I don't believe that anybody will ever write a cross-platform Basic environment to be shipped with OOo.

It already exists, or isn't it cross-platform?
But it is slow, leaking memory, buggy and strictly procedural

VBA is object-oriented as well as Star Basic. Possibly it has not as many object-oriented features as VB.NET has, but nonetheless it is so.
This is why I mentioned Python as one alternative.

Nothing bad with Python, but I do not know it and I know nobody who does.
Nxx
 
Posts: 10
Joined: Thu Dec 13, 2007 1:22 pm

Re: Basic

Postby Nxx » Sat Dec 15, 2007 3:22 pm

DrewJensen wrote:well, not sure where you read that at. VBA and OOoBasic are very different - more so then even VBA and VB6 different from each other.


I read it here:http://docs.sun.com/app/docs/doc/819-0439/faagh?q=staroffice+8&a=view

Compatibility between StarOffice Basic and VBA relates to the StarOffice Basic language as well as the runtime library. The StarOffice API and the Dialog Editor are not compatible with VBA (standardizing these interfaces would have made many of the concepts provided in StarOffice impossible).


VBA and VB6 are essentially the same language.
Nxx
 
Posts: 10
Joined: Thu Dec 13, 2007 1:22 pm

Re: Basic

Postby DrewJensen » Sat Dec 15, 2007 3:33 pm

OK - well I had to ask didn't I.

First thing is that StarOffice and OpenOffice.org are not identical programs. One of the Value Added features of the, until recently, commercial only version of StarOffice has been deeper VBA support. Still, one could interpret how much interoperability there is between the languages.

My best advice would be - Download a free copy of StarOffice from Google - grab some of your VBA libraries - copy and paste these into the OOoBasic IDE and see how much runs. All it will cost you is some bandwidth and a little time.
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Basic

Postby RonIA » Sat Dec 15, 2007 3:51 pm

My 2 cents, (.01 euros, 2 pence, etc.)

The arguements (OK, discussions) here about differences in VBA, VB6, StarBasic, QuickBasic, etc.

The main differences are in how they relate to the various objects (i.e. how do I pluck a value out of a combo box on a form for example). However, these are the "big problems" for new developers. In general the Basic constructs themselves are "basically" the same.

For x=0 to 9
Next x

But if you are trying to refer to 10 different cells on a single spreadsheet, or the same cell in 10 different spreadsheets, that is where the true differences lie. Basic is Basic, C is C, Python is Python...

This is the dilemma I am in. I am an intermediate MS Access developer that is having a hard time transitioning to OO.o Base because I can't seem to get my head around how do I pick up a value from a specific control on a database form, process it and put it in a different control; or some such transformation.

VBA?
Can be as simple as
me.txtSecondControl = me.cboFirstControl & ", w00t"

No such luck for this simplicity in OO.o Base, unless they have put the "Obscure control reference from Ron" feature to True by default. ;)
Ron from Iowa, USA
RonIA
Volunteer
 
Posts: 139
Joined: Mon Oct 08, 2007 1:34 am
Location: Iowa USA

Re: Basic

Postby Villeroy » Sat Dec 15, 2007 4:20 pm

Nxx wrote:
I don't believe that anybody will ever write a cross-platform Basic environment to be shipped with OOo.

It already exists, or isn't it cross-platform?

The "surrounding" office with it's own graphic tool kit provides everything. I believe there is not much platform specific code in StarBasic. TerryE could tell us more about it.
Nxx wrote:
But it is slow, leaking memory, buggy and strictly procedural

VBA is object-oriented as well as Star Basic. Possibly it has not as many object-oriented features as VB.NET has, but nonetheless it is so.

You can not define classes. Without helper function createUnoListener you could not even listen to events because this requires attaching a listener object to an UNO-object. StarBasic without class modules is 100% procedural like VBA in MSOffice '95 was. You can't even write real add-ins in StarBasic because you can not implement classes with support of certain add-in interfaces (add-ins is the term for extensions containing integrated, localizable spreadsheet functions).
Nxx wrote:
This is why I mentioned Python as one alternative.

Nothing bad with Python, but I do not know it and I know nobody who does.

Python is the most simple language I've ever seen. Translation from/to StarBasic is extremely simple in most cases (Python code is shorter and easier to read than Basic). Any decent code-editor with a debug facility is far better than OOo's StarBasic IDE.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26401
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Basic

Postby Nxx » Sat Dec 15, 2007 4:25 pm

DrewJensen wrote:OK - well I had to ask didn't I.

First thing is that StarOffice and OpenOffice.org are not identical programs. One of the Value Added features of the, until recently, commercial only version of StarOffice has been deeper VBA support. Still, one could interpret how much interoperability there is between the languages.

My best advice would be - Download a free copy of StarOffice from Google - grab some of your VBA libraries - copy and paste these into the OOoBasic IDE and see how much runs. All it will cost you is some bandwidth and a little time.

I think it will not run because Star Office and MS Office have different APIs. As it mentioned above it is not possible to make the APIs equal. But I did talk about the language itself, not Office APIs. The language itself and runtime libraries are compatible with VBA and as such, with VB6.
Nxx
 
Posts: 10
Joined: Thu Dec 13, 2007 1:22 pm

Re: Basic

Postby Nxx » Sat Dec 15, 2007 4:30 pm

RonIA wrote:My 2 cents, (.01 euros, 2 pence, etc.)

The arguements (OK, discussions) here about differences in VBA, VB6, StarBasic, QuickBasic, etc.

Not Quick Basic.

RonIA wrote:The main differences are in how they relate to the various objects (i.e. how do I pluck a value out of a combo box on a form for example). However, these are the "big problems" for new developers. In general the Basic constructs themselves are "basically" the same.

For x=0 to 9
Next x

But if you are trying to refer to 10 different cells on a single spreadsheet, or the same cell in 10 different spreadsheets, that is where the true differences lie. Basic is Basic, C is C, Python is Python...

This is Office APIs. For a stand-alone Basic program it is irrelevant.
Nxx
 
Posts: 10
Joined: Thu Dec 13, 2007 1:22 pm

Re: Basic

Postby DrewJensen » Sat Dec 15, 2007 4:37 pm

Villeroy makes Good points -

I have to admit that I only recently started taking a very long look at Python - because of another FOSS application I have started to use a fair bit, written entirely in Python. Currently trying to lay my fist egg...LOL.

The only knock I would give it is directly relating to StarOffice - not part of the distro - I think you can add it in after the fact, but not sure. There is a discussion about that point right now on the extensions dev mailing list actually.

Back to Basic however -

Yes but most of what you do in a library of any size is going to be bound closely to the API. I will tell you that there is still work going on to add more direct support for VBA in OpenOffice.org and StarOffice.

Bottom line - I'm not saying you should abandon Basic just that if you are expecting to get a lot of re-use of existing VB code directly in OpenOffice.org you are most likely going to be disappointed - it is going to require a good bit of translation. ( Sun does have a tool to help with that, but I believe that is still only available as part of the For $$ version and not part of the free version from Google )
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Basic

Postby Nxx » Sat Dec 15, 2007 6:56 pm

No I do not say about pre-existing code in VBA. In fact hypotetically there is a lot of code in VB6, but Star Office APIs are irrelevant for it. I wander is it possible to grab the Basic from SO and make a VB6 replacement for all those who disappointed with MS-enforced transition to VB.NET. Also it would be great it there was a stand-alone open-source modern Basic compiler/interpreter to use both as an IDE for various applications, as a scripring tool for open-source operating systems and as an automation tool for various third party office-like applications (like VBA is used by third-party developers to embeed it into their applications).
Nxx
 
Posts: 10
Joined: Thu Dec 13, 2007 1:22 pm

Re: Basic

Postby RonIA » Sat Dec 15, 2007 8:53 pm

OK, maybe we are straying from the original intent of the OP. Here I risk a flame war.

Nxx,
You want an open source, free (as in freedom and/or beer) Basic interpreter for general purpose programming use. I distill this because you want to run it separately from OpenOffice.org.

I think you are trying to use this tool for much more than it was ever intended. The built in Basic and included IDE is primarily designed to automate interactions with the office suite. Even if you can get it to do what you want without an integration with the rest of OO.o you are stretching the intent of the development environment.

Just like OO.o Calc can be used as a very bare-bones database, or OO.o Writer can be used to create newsletters... They were not designed to perform these functions. If you try to use an application beyond its intended purpose you will likely have to work much harder than if you choose a more appropriate tool.

VBA is meant to interact with Microsoft Office. VB6 is a general purpose programming language meant to do anything. StarBasic is meant to interact with StarOffice / OpenOffice.org. There are a number of Basic IDE's available that are stand alone. My suggestion is look elsewhere for a stand alone interpeter / compiler for your Basic programming needs. If you want to program with StarOffice / OpenOffice.org feel free to use what is built in specifically to interact with it, StarBasic.

It's not a Basic vs. Python vs. Java discussion here, it is trying to use an integrated component of an office suite.

Do a search on the Internet for "Open Source Basic Interpreters" or just go to Wikipedia Basic Dialects.

Donning flame-proof suit and signing off.
Ron from Iowa, USA
RonIA
Volunteer
 
Posts: 139
Joined: Mon Oct 08, 2007 1:34 am
Location: Iowa USA

Re: Basic

Postby Nxx » Sat Dec 15, 2007 10:20 pm

In fact what is needed for general purpose IDE is the engine. The engine exists in the OOo Basic. VBA, VBScript and VB all built on the base of one engine. There is no need to re-write engine for those different applications.

One another interesting question is somebody able to create their own office suit/other application and embeed OOo Basic in it as a macro/automation tool?
Nxx
 
Posts: 10
Joined: Thu Dec 13, 2007 1:22 pm

Re: Basic

Postby RonIA » Sun Dec 16, 2007 2:27 am

My assumption would be yes. Would have to read the GPL and any other licenses that cover the software and make sure what you are doing is within those limits.
Ron from Iowa, USA
RonIA
Volunteer
 
Posts: 139
Joined: Mon Oct 08, 2007 1:34 am
Location: Iowa USA

Re: Basic

Postby Evgenych » Sat Jan 26, 2008 4:17 pm

soffice.exe ".uno:BasicIDEAppear" - open Basic IDE via command line
(from http://www.openshortcut.org/ooo/function-uno.php)
Evgenych
 
Posts: 2
Joined: Fri Jan 04, 2008 6:00 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 1 guest