About VBA-UserForms

@everyone guru:

While making a deeper diving into my old Excel/VBA tuning to study what in earth I had in mind when coding. I found image data in my database stored as a byte array in one of its fields.
Now I ran into a new challenge. Namely, (Star) Basic can’t convert a byte array to string, like in VBA
imgstr = Space(Ubound(bytes))
imgstr = StrConv(bytes, vbUnicode) and so on…
So I have to ask the community gurus whether there’s a service included in UNO which could handle this conversion.

@everyone

I found the reason for this last one problem of which I wrote. It depends on ASR rules set by the Windows Defender. The “firm” also implemented this policy in Windows 10 with the latest feature update sometime in the summer of 2024. So you couldn’t take advantage of API functions included in the msvbvm60.dll library anymore which were the most useful functions when coding macros with LibreOffice Basic on Windows platform. But this is nothing to worry about in case you have access to the Windows Group Policy Manager, or you can alternatively use a 3rd party app for example like DefenderUI which can be downloaded from the “firm’s” store free of charge.

MultiPageControl is documented in ScriptForge.Dialogs.Dialog Page property and SetPageManager method.
Feel free to use it !

Thanks a lot :slightly_smiling_face:

You are exceptionally smart! ROFL

Well, you have to start somewhere :wink:

Dynamic dialogs support tabs, although the dialog editor does not expose them.

Checking listeners from below example may help:

@LibreOfficiant

Thx for this, even though I had already decided to forget everything related to Phyton for good :wink:

@Pertsa
Apologies for not being preciser. Tabbed dialog are supported using Basic as per “Demo v2.odt” example in
https://forum.openoffice.org/en/forum/viewtopic.php?t=76818&hilit=tabpagecontainer
You’ll have to build dynamic dialogs in place of static ones.

1 Like

Thx for this :slightly_smiling_face:

Here’s a working demo ported to [Star]Basic, based on my old VBA tuning.
MHLO 2.0.ods (42.3 KB)
To test functionality better you can download a .zip package containing 2 .xml files related to tuning and a READ ME.txt which explains the main.
I didn’t translate the labels above the controls (e.g. into English) because purpose of this demo is just to show how to get the feel of a tabbed interface with a little bit of cheating.

I finally got this to work the way it did in my original VBA tuning (with the MutiPage control)
MHLO 2.0.2.ods (37.6 KB)
In case you want to test, use .xml files (SenderData.xml and ReceiverDatabase.xml) which you can download by clicking this link.

If you happened to be interested in, you can watch how my tuning works by clicking this link.
I didn’t include the functionality of Special handling/Details tab to this demo related to customs clearance, transportation of dangerous goods, etc.

Here one more update of my tuning. This time I have not used any Windows API calls, nor COM objects for XML handling or HTTP request with POST method. The only external tool used is curl for sending XML data to Oy Matkahuolto Ab server with HTTP request using POST method.

MHLO 2.0.3.ods (38.0 KB)

If you happen to be interested in testing a .zip package can be downloaded containing some XML data related to tuning and server response.

More ideas…
While spinning the ideas I got while recoding my tuning I realized that I could extract data from .xml files stored into my LO project’s package and store the extracted data to string variables on the fly. This gives me ability to manipulate the data the way I want and then save the manipulated data either back to the project package or to some other target like a single file or a package archive.

The first step on this was to create a macro to read data:
There are no easy to find examples available how this could be done, and it took a while until I came across Andrew Pitonyak’s documentation which handled among many other things TextInputStream object. Andrew’s explanation of how to extract the data into a string wasn’t the easiest to understand, in the case you want to read the data into string at once instead of doing it line by line in a do-while-loop.
But finally I got it:

Sub BasicMain
    ExtractSpecificFileFromProjectAchiveAsText "Dialogs/Standard/", "MultiPageTemp.xml"
End Sub

Sub ExtractSpecificFileFromProjectAchiveAsText(sFolder As String, sFile As String)

    Dim oZipHandler As Object
    Dim args(0)
    Dim args1()
    Dim entries() As String
    Dim xmlContent As Variant
    Dim fileToRead As String
      	
    fileToRead = sFolder & sFile
    oZipHandler = CreateUnoService("com.sun.star.packages.zip.ZipFileAccess")
    args(0) = thisComponent.URL
    oZipHandler.initialize(args)
    
    entries = oZipHandler.getElementNames()
    Dim textStream As Object
    textStream = CreateUnoService("com.sun.star.io.TextInputStream")
    Dim stream As Object, line As String
    
    For i = LBound(entries) To UBound(entries)
        If entries(i) = fileToRead Then
            stream = oZipHandler.getByName(entries(i))
            textStream.setEncoding("UTF-8")
            textStream.setInputStream(stream)
            xmlContent = textStream.readString(args1, true)
            textStream.closeInput()
            textStream = Nothing
            stream = Nothing
            Erase entries
            args = ""
            Erase args1
            oZipHandler = Nothing
            Exit For
        End If
    Next 

    MsgBox "Extracted content: " & chr(10) & xmlContent

End Sub

This offers an opportunity to extremely expand what can be done just using pure Basic.

Hello!
You can work with the xml file from the document archive right away, as it is done here.
In this case, you will be pleased to know that the DocumentBuilder service provides the same methods as the Microsoft DOMDocument object.
An alternative is to use Python with its countless built-in capabilities.

@sokol92

Thx for your tip.
But I use my own built string builder/xml handler. By doing this I’m able to step aside from UNO controlling almost completely.

EDIT:
Here’s an example that clearly explains that recycling data through DomBuilder - Dom is unnecessary and would only slow down the process:

Option VBASupport 1

Private originalStr As String
Private pageTmpStr As String
Private buildStr As String

Sub StarToWork

	Dim tmpStr As String, spos  As Long,  epos  As Long
	originalStr = GetTempTabPage
	MsgBox "The original:" & chr(10) & originalStr
	spos = InStr(originalStr,"<dlg:page")
	MsgBox spos
	epos = InStr(originalStr, chr(34) & "Page1" & chr(34) & "/>") + Len(chr(34) & "Page1" & chr(34) & "/>")
	MsgBox epos
	pageTmpStr = Mid(originalStr, spos, epos - spos)
	MsgBox pageTmpStr
	buildStr =  Replace(originalStr, chr(34) & "Page1" & chr(34) & "/>", chr(34) & "Page1" & chr(34) & ">" & chr(10) & _
	"You can put  here whatever content you want." & chr(10) & "I'll use manipulated data read from a Dialog (xml) inside the project package" & chr(10) & _
	"which mimes content of a Tab page. Tip everything between tag <BulletinBoard></BulletinBoard> including the start and end tag" _ 
	& chr(10) & "</dlg:page>" & chr(10) & Replace(pageTmpStr, "Page1", "Page2")) 'and so on...
	MsgBox buildStr
	MsgBox "You may guess what I do with BuildString when I'm happy with the result...."
End Sub


Function GetTempTabPage() As String

	GetTempTabPage = _
"<?xml version=""1.0"" encoding=""UTF-8""?>" & chr(10) & _
"<!DOCTYPE dlg:window PUBLIC ""-//OpenOffice.org//DTD OfficeDocument 1.0//EN"" ""dialog.dtd"">" & chr(10) & _
"<dlg:window xmlns:dlg=""http://openoffice.org/2000/dialog"" xmlns:script=""http://openoffice.org/2000/script"" dlg:style-id=""1"" dlg:id=""MultiPage_Template"" dlg:left=""0"" dlg:top=""0"" dlg:width=""331"" dlg:height=""253"" dlg:closeable=""true"" dlg:moveable=""true"">" & chr(10) & _
 "<dlg:styles>" & chr(10) & _
  "<dlg:style dlg:style-id=""0"" dlg:background-color=""0xece9d8""/>" & chr(10) & _
  "<dlg:style dlg:style-id=""1"" dlg:background-color=""0xdee6ef""/>" & chr(10) & _
 "</dlg:styles>" & chr(10) & _
 "<dlg:bulletinboard>" & chr(10) & _
  "<dlg:multipage dlg:style-id=""0"" dlg:id=""MultiPage1"" dlg:tab-index=""0"" dlg:left=""27"" dlg:top=""23"" dlg:width=""272"" dlg:height=""195"" dlg:value=""4"">" & chr(10) & _
   "<dlg:bulletinboard>" & chr(10) & _
    "<dlg:page dlg:style-id=""0"" dlg:id=""Page1"" dlg:tab-index=""0"" dlg:visible=""false"" dlg:left=""1"" dlg:top=""21"" dlg:width=""249"" dlg:height=""173"" dlg:title=""Page1""/>" & chr(10) & _
   "</dlg:bulletinboard>" & chr(10) & _
  "</dlg:multipage>" & chr(10) & _
 "</dlg:bulletinboard>" & chr(10) & _
"</dlg:window>" & chr(10)
End Function

In addition, my response to all those who so enthusiastically advertise the excellence of Python:
As for me, I have isolated Python already for a long ago by zipping the executable, renaming the zip and deleting the original. I don’t give a shit about anything that separates you from knowing the underlying fundamentals. In my opinion sooner or later it leads to a situation where everyone has turned into a herd of cows without any innovativeness. It’s like being in a church where the priest tells you how to live your life while they’re collecting the money…

Your enthusiasm for finding previously untrodden paths is commendable. Having alternative solutions gives us more options when choosing. :slight_smile:

Until the day you only have one option to choose from :upside_down_face: