New Collection and Dictionary like VBA

Creating a macro - Writing a Script - Using the API
Post Reply
nicgiard
Posts: 7
Joined: Mon Feb 25, 2008 12:09 am

New Collection and Dictionary like VBA

Post by nicgiard »

In VBA is very simple to have owner generic container as Collection ( New Collection in VBA ) or Dictionary ( new Dictionary from link MSScript in scrrun.dll ), or manipolate Xml DomDocument with MsXml.dll.
And in Openoffice ???. This is very important for advanced programming.
Thank you :geek:
User avatar
Villeroy
Volunteer
Posts: 30612
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: New Collection and Dictionary like VBA

Post by Villeroy »

Use a better programming language such as Java or Python. You get even more than VB has to offer.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
nicgiard
Posts: 7
Joined: Mon Feb 25, 2008 12:09 am

Re: New Collection and Dictionary like VBA

Post by nicgiard »

It's a good idea.
I am an amateur and Unfortunately I am too old for improve others languages :| .
It's so difficult to improve OpenOffice Basic with linking to external library ????
thank you
User avatar
Villeroy
Volunteer
Posts: 30612
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: New Collection and Dictionary like VBA

Post by Villeroy »

A very valuable member of the community did some creative experiments with Python containers, callable from Basic. I could not get it working, though: http://www.oooforum.org/forum/viewtopic ... =container
I learned Python during a rainy weekend, enough to write simple backup scripts and office macros. If you've got the concept of object orientation, it is by far more easy than stupid old Basic (and you can use decent editors). No more Empty,Null,Nothing,IsMissing,Dim,Redim,DimArray,sub/function and other nonsense.
One day study: http://www.swaroopch.com/byteofpython/
Another day with other people's examples:
http://wiki.services.openoffice.org/wik ... ent_python
http://wiki.services.openoffice.org/wik ... o_language
http://wiki.services.openoffice.org/wiki/PyUNO_bridge
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
nicgiard
Posts: 7
Joined: Mon Feb 25, 2008 12:09 am

Re: New Collection and Dictionary like VBA

Post by nicgiard »

i have seen for python...., is very interesting....

But, why do not use :shock:
Set automationFactory = createUnoService("com.sun.star.bridge.oleautomation.Factory")
Dim objApp As Object
Set objApp = automationFactory.createInstance("Scripting.Dictionary")
It seems good !!! (Its true, needs to use MSWindows, in this case why not ???)
Are there another like this ???
thank you for your answers :lol:
User avatar
Villeroy
Volunteer
Posts: 30612
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: New Collection and Dictionary like VBA

Post by Villeroy »

I can't tell. No windows, no com.sun.star.bridge.oleautomation.Factory.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
tani
Posts: 3
Joined: Thu Jun 12, 2008 5:06 am

Re: New Collection and Dictionary like VBA

Post by tani »

I tried just now on WindowsXP + OOo3(Basic).
If "VBASupport" to enable, "Collection" objects can be used.

Example:

Code: Select all

Option VBASupport 1
Sub Main
  Dim test As Collection
  Set test = New Collection

  test.Add("foo", "1")
  msgbox test(1)
End Sub
OOo 2.3.X on Ms Windows XP + Ubuntu
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area
Contact:

Re: New Collection and Dictionary like VBA

Post by B Marcelly »

tani wrote:I tried just now on WindowsXP + OOo3(Basic).
If "VBASupport" to enable, "Collection" objects can be used.
This is not specific to OOo 3, you don't need VBASupport.
It is just another syntax to call the Collection object from MS-Windows, using COM.
Here is a simpler syntax:

Code: Select all

Dim test As New Collection
test.Add("foo", "1")
msgbox test(1)

'  calling an object from MS-Windows follows the same syntax
Dim fso As New Scripting.FileSystemObject
MsgBox("Number of drives : " & fso.Drives.Count)
 Edit:  see my next message in this thread.
______
Bernard 
Last edited by B Marcelly on Fri Feb 06, 2009 4:33 pm, edited 2 times in total.
tani
Posts: 3
Joined: Thu Jun 12, 2008 5:06 am

Re: New Collection and Dictionary like VBA

Post by tani »

I see, Thanks much. :D
OOo 2.3.X on Ms Windows XP + Ubuntu
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area
Contact:

Re: New Collection and Dictionary like VBA

Post by B Marcelly »

Hi,
Another thread shows more information about Collections in OOoBasic.
They are available from 2.4 and not restricted to MS-Windows.

Here is an example of a simple dictionnary. The purpose is to find the postal code of a given town.

Code: Select all

Sub DictionaryExample
Dim k As String
Dim dico As New Collection
dico.Add("49000", "Angers") ' key = "Angers", Item = "49000"
dico.Add("33000", "Bordeaux")
dico.Add("09000", "Foix")
dico.Add("11350", "Cucugnan")
MsgBox("Number of elements : " & dico.Count)
Do
  k = InputBox("Town : ", "Find postal code", "")
  if Len(k) = 0 then Exit Do
  On Error GoTo inconnu
  MsgBox("Postal code : " & dico(k) )  ' the key is not case sensitive
  suite1:
  On Error GoTo 0
Loop
Exit Sub

inconnu:
  MsgBox("Town  " & k & "  is unknown", 16)
  Resume Suite1
End Sub
I could not find a function to test the existence of a key. So I use error handling to detect not-existing keys.
______
Bernard
Post Reply