Yay Basic!!

So Basic was NOT there in the beginning, but lets face it, it still around. OpenOffice.org re-implement basic on their enviroment to appeal to the new users for the ‘simple’ and well… basic syntax.

However the OpenOffice.org API is far from simple and a lot of documentation and even more important, exposure is needed on how to master this language.

I have been fliying around this issue for a while, as the leader of the spanish community, I had spotted a lot of interest in learning Basic and mastering the macros and making OOo a more automated solution.

The issue is the badly organized documentation that have seen to slow down the development of OOo really. I have on the other hand seen a few developers that have scale up to become serious players for extending OOo programatically.

I had spent this past weeks reading in more detal Andrew Pitonyak documentation and tirying to make sense of it. I have also been writing articles in regards to Laurent Gogard’s famous macros and have been puting also my personal thought about how things might be working.

Like many say, the only way to learn is by doing it. And to learn the API you really need to develop something. Put a goal and try whatever it takes to achieve it.

I have some goals and will list them here, but what is most important is the community itself to have their own goals and to try to achieve them. This will include dipping into oooforum.org and all the wikis, and documentation available and either translate it for the ones coming after, or actually start coding on it.

Basic reagardless of their humble origins is a true player in the UNO space. Some of this merits are basically that the implementation was builted wiht the API in mind which means that less code is needed to do stuff compared wiht external languages like Java, etc.

So far I have started to get some code out and write about the questions that had come to mind and even twent as far to write down questions about it.

The code was taken from Andrew’s document. I tried a bunch but just comment on a few. Here is the code with some of my anotations.

To create an instance of a service, use the global method createUnoService() as shown in Listing 3.6. This also demonstrates how to create a structure.
Listing 3.6: This is the old way of executing a dispatch.

Sub PerformDispatch(vObj, uno$)  Dim vParser    ' This will reference a URLTransformer.  Dim vDisp      'Return value from the dispatch.  Dim oUrl As New com.sun.star.util.URL   'Create a Structure  oUrl.Complete = uno$  vParser = createUnoService("com.sun.star.util.URLTransformer")   vParser.parseStrict(oUrl)   vDisp = vObj.queryDispatch(oUrl,"",0)   If (Not IsNull(vDisp)) Then vDisp.dispatch(oUrl,noargs())End Sub

My first questions is regarding how old is this dispatcher is it from OOo 1.x or 1.1.x.
I ran this and gave me an error in 2.0 at line 5 of the code saying:
Execution fault the argument is not optional
The call was also labeled as 0: PerformDispatch.

Andrew pretty much nail it here, on why OOoBasic is so challenging:

Writing macros in OpenOffice.org (OOo) is a complicated task with a steep learning curve. The problem is not the base language or the environment, it is the OOo application programming interface (API). The base language refers to the syntax and the commands that are not used to interact with an OOo document. page10 / 30

For this issue there are tools called Property Inspectors, the most common and famous in the community is PyXray and Xray which basically list all the services with their methods and help developers get a reference of the API.

When users use the macro recoder they are using a dispatcher which has some limitations, this limitations have been going away. At one point the user could only record things happening on the working area but not on dailogs and/or options that need another dialog.

Recently this has been fixed, however the use of a dispatcher is from conception limited as opposed to the freedom to type whatever function you want.

Also a dipatcher is tight to the user interface which could not e a good platform when you ldont have a UI presenta and want to deploy a service for example where the properties are not on the dipatcher since they are not avaialbe as an option for the user. For example, loading a document from a URL, like OOoDic does.

They attempt to fix it here with a DispatchProviderInterceptor which is supposed to intercept all the calls made by the mouse so the recorder is not halted by a new dialog or some options within that the dispatcher can’t make out of it.

At the end I was full of information but the information didnt really connect, I came to the conclusion that we need more tutorials that can complement this refferences and snippets.

I guess a good way to understand is to build tutorials and HOWTO going into the why’s and why nots about the code. Some miscelaneous doubts I remain were:
– Does the use of lowercaps / caps influence on the syntax?
– What exactly does %n and %i
– Is there a float type variable, because i got some errors about not being so.
– What are commands like, – createEnumeration(), hasmoreElementsm(), nextElement(), getElementNames, getByName.
– How can I tell what type of variable do I need?

As I go on reading the Basic Language reference I hope at least 70% of this doubts clear a bit. Till then, I guess we need more community involemnte to share the knowledge.