Macro Dim Dialog and Control

Hi!

I'm experimenting with extended data types in Calc Basic. I found some
information about it, which only gave me two different examples without any
link or anything to the rest of the ”new” data types available, so I'm
searching the best I can, so far coming up with a few ideas that all failed.

Without the feature enabled I Dim everything as Object, for instance:
Dim oSheet As Object
Dim oCell As Object
Dim Col As Long, Row As Long: Row = 35 : Col = 42
Dim oDlg As Object
Dim oCtl As Object
oSheet = ThisComponent.getSheets().getByName("MySheet")
oCell = oSheet.getCellByPosition(Col, Row)
oDlg = CreateUnoDialog(DialogLibraries.Standard.MyDialogue)
oCtl = Dlg.getControl("MyComboBox")

With the extended data types enabled, the first two lines would rather look
like this:
Dim oSheet As com.sun.star.sheet.XSpreadsheet
Dim oCell As com.sun.star.table.XCell

This works, but what about oDlg and oCtl? Are there special data types for
them too? The documentation I've found so far doesn't give any hints at
all. I tried this:
Dim Dlg As com.sun.star.awt.XDialog ' No error here,
' but next line throws an error:
oDlg = CreateUnoDialog(DialogLibraries.Standard.MyDialogue)
' Error: No access to object.
' Invalid usage of the object.
' Well, something like that, it's actually in Swedish.

I can still do Dim As Object and it works, but since I'm trying out the new
data types this isn't it…

Can anyone point me to some kind of reference manual for those new data
types?

Kind regards

Johnny Rosenberg

Hi Jonny,

This works, but what about oDlg and oCtl? Are there special data types for
them too? The documentation I've found so far doesn't give any hints at
all. I tried this:
Dim Dlg As com.sun.star.awt.XDialog ' No error here,
' but next line throws an error:
oDlg = CreateUnoDialog(DialogLibraries.Standard.MyDialogue)
' Error: No access to object.
' Invalid usage of the object.
' Well, something like that, it's actually in Swedish.

What is the name of the dialog? Is ist called "MyDialogue"?. It should
appear at the left (catalog of objects - don't konwo if this is the
right name ..) and at the bottom (like the standard "Module1")

Declare the dialog first, out of a sub:
DIM oDialog0 AS OBJECT

Start the dialog:

SUB Dialog0Start
DialogLibraries.LoadLibrary("Standard")
oDialog0 = createUnoDialog(DialogLibraries.Standard.Dialog0)
oDialog0.Execute()
END SUB

Name of the dialog is "Dialog0"

End the dialog:

SUB Dialog0Ende
oDialog0.EndExecute()
END SUB

Regards

Robert

Oops, sorry. I did it again, I accidentally replied privately rather than
to the list. I'm sorry for that, Robert.

Sorry, using my phone for this... And off the top of my head...

Each object usually supports multiple interfaces...

In basic, the actual type does not matter.

Names starting with an x refer to an interface.

I need to look it up, but I think that the preference was a variant rather than object, but...

It may no longer matter

The developer who told me this could not remember why it when it mattered

And

I only had a problem because of it once, and that was years ago.

Other languages, like Java, it matters. I'd we had a smarter IDE it might be useful to declare the actual type.

⁣Sent from BlueMail ​

Sorry, using my phone for this... And off the top of my head...

Each object usually supports multiple interfaces...

In basic, the actual type does not matter.

Names starting with an x refer to an interface.

I need to look it up, but I think that the preference was a variant rather
than object, but...

It may no longer matter

The developer who told me this could not remember why it when it mattered

And

I only had a problem because of it once, and that was years ago.

Other languages, like Java, it matters. I'd we had a smarter IDE it might
be useful to declare the actual type.

According to the little information I found, types like Variant and Object
are considered slow. Probably fast enough for most situations, but fast is
never a bad thing, is it?
Also, I'm trying out the other new "experimental" features as well, such
as… whatever that's called in English… code expansion? Text expansion? That
is, when I type I get suggestions. This only work with the new extended
data types.

I work with VBA in Excel at work (that's what they have so that's what I
must use), and I kind of miss that feature. In LibreOffice, it means that I
don't have to use xray as much as otherwise. Another minor thing I miss
from Excel VBA, is that I can see the value of a variable by just hovering
the mouse pointer over it. Excel has a lot of nasty bugs though, I don't
miss them… :stuck_out_tongue: Not said that LibreOffice Calc is bugfree in any way, there
are some, there too.

Anyway, at the moment I'm only experimenting with it, just for fun, but it
would be nice to see some documentation of all this. If examples are
included – even better.

Kind regards

Johnny Rosenberg

I left this question behind for quite a while, but now I experimented a bit
more with it and I came up with the following macro example, which works
for a dialogue called ”ElDialog” including a date field called ”DateField”
that has to be created before running the macro:

Sub test
    Dim oDlg As com.sun.star.awt.XUnoControlDialog
    Dim oCtl As com.sun.star.awt.XDateField
    DialogLibraries.LoadLibrary("Standard")
    oDlg=CreateUnoDialog(DialogLibraries.Standard.ElDialog)
    oCtl=oDlg.getControl("DateField")
    Dim oDate As com.sun.star.util.Date
    oDate=createUnoStruct("com.sun.star.util.Date")
    oDate.Year=2018
    oDate.Month=9
    oDate.Day=2
    oCtl.setDate(oDate)
    oDlg.execute
End Sub

So the dialogue can obviously be declared as
com.sun.star.awt.XUnoControlDialog.
When it comes to controls, i tdepends on what type of control. For a date
field, com.sun.star.awt.XDateField seems to be it.

For this to work, the enhanced IDE features must be enabled.
I can also declare a date as com.sun.star.util.Date, rather than just Object.
When doing that, I get suggestions as I type. In the case above, when I
type ”oDate.”, I get Day, Month and Year as suggestions. That makes the
whole thing a little bit easier, I think. Maybe the macro also runs a
little faster, I don't know.