New Collection and Dictionary like VBA

Creating a macro - Writing a Script - Using the API

New Collection and Dictionary like VBA

Postby nicgiard » Mon Feb 25, 2008 12:51 am

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:
nicgiard
 
Posts: 7
Joined: Mon Feb 25, 2008 12:09 am

Re: New Collection and Dictionary like VBA

Postby Villeroy » Mon Feb 25, 2008 1:22 am

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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27207
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: New Collection and Dictionary like VBA

Postby nicgiard » Mon Feb 25, 2008 9:00 pm

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
nicgiard
 
Posts: 7
Joined: Mon Feb 25, 2008 12:09 am

Re: New Collection and Dictionary like VBA

Postby Villeroy » Mon Feb 25, 2008 9:23 pm

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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27207
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: New Collection and Dictionary like VBA

Postby nicgiard » Thu Feb 28, 2008 1:05 am

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:
nicgiard
 
Posts: 7
Joined: Mon Feb 25, 2008 12:09 am

Re: New Collection and Dictionary like VBA

Postby Villeroy » Thu Feb 28, 2008 1:33 am

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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27207
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: New Collection and Dictionary like VBA

Postby tani » Thu Nov 20, 2008 3:02 am

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

Example:
Code: Select all   Expand viewCollapse view
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
tani
 
Posts: 3
Joined: Thu Jun 12, 2008 5:06 am

Re: New Collection and Dictionary like VBA

Postby B Marcelly » Thu Nov 20, 2008 3:06 pm

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   Expand viewCollapse view
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.
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: New Collection and Dictionary like VBA

Postby tani » Thu Nov 20, 2008 5:27 pm

I see, Thanks much. :D
OOo 2.3.X on Ms Windows XP + Ubuntu
tani
 
Posts: 3
Joined: Thu Jun 12, 2008 5:06 am

Re: New Collection and Dictionary like VBA

Postby B Marcelly » Fri Feb 06, 2009 4:30 pm

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   Expand viewCollapse view
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
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 8 guests