BASIC extension with progress bar

Hello world extension

I’m going to modify the following hello world BASIC extension. It has a BASIC script here:

Progress bar

I have the BASIC code and also the XML dialog for a progress bar that I borrowed from here: BASIC|Calc: Progress bar - #3 by Ratslinger

I need to add the following BASIC code and XML dialog of the progress bar example to the above hello world extension.

Progress bar code

REM  *****  BASIC  *****

Option Explicit

Sub ProgressBarDemo()
	Dim oProgressBar as Object, oProgressBarModel As Object, oDialog as Object
	Dim ProgressValue As Long
	Dim oSheet as Object
	Dim oCell as Object
    Dim ProgressValueMin as Integer
    Dim ProgressValueMax as Integer
	REM Dialog1 contains progress bar ProgressBar1 saved in standard library
	DialogLibraries.loadLibrary("Standard")
	oDialog = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
	REM progress bar settings

    ProgressValueMin = InputBox ("Please enter a starting value:","Input Required")
    ProgressValueMax = InputBox ("Please enter a ending value:","Input Required")

'	Const ProgressValueMin = 0
'	Const ProgressValueMax = 40
	Const ProgressStep = 4
	REM set minimum and maximum progress value
	oProgressBarModel = oDialog.getModel().getByName( "ProgressBar1" )
	oProgressBarModel.setPropertyValue( "ProgressValueMin", ProgressValueMin)
	oProgressBarModel.setPropertyValue( "ProgressValueMax", ProgressValueMax)
	REM show progress bar
	oDialog.setVisible( True )
	REM increase progress value every second

    oSheet=thiscomponent.getcurrentcontroller.activesheet
    oCell=oSheet.getCellByPosition(0,9)


	For ProgressValue = ProgressValueMin To ProgressValueMax Step ProgressStep
		oProgressBarModel.setPropertyValue( "ProgressValue", ProgressValue )

REM This is where you perform whatever action you are wanting

        oCell.SetString(ProgressValue)
		Wait 1000
	Next ProgressValue
    oCell.SetString("Done")
End Sub

Progress bar dialog

And this file named Dialog1.xdl with this content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="Dialog1" dlg:left="13" dlg:top="11" dlg:width="197" dlg:height="78" dlg:closeable="true" dlg:moveable="true">
 <dlg:bulletinboard>
  <dlg:progressmeter dlg:id="ProgressBar1" dlg:tab-index="0" dlg:left="15" dlg:top="41" dlg:width="170" dlg:height="22"/>
  <dlg:text dlg:id="Label1" dlg:tab-index="1" dlg:left="15" dlg:top="14" dlg:width="55" dlg:height="9" dlg:value="Progress -----"/>
 </dlg:bulletinboard>
</dlg:window>

Question

I have tried some approaches but none worked. I’m getting confused about how to add the progress bar example to the hello world extension. I’d apreciate any hint or help. Thanks.

I understand your difficulty,

I would say
if I understood
what your difficulty is.

Your second question about extensions seems like an attempt at trolling.

Where in the program that displays on the screen the message “Hello, world!” is it possible to attach a progress bar? And why? How is this supposed to work?

If you need to hang a bookshelf, then it is better to ask “How to hang a bookshelf?”

If you instead ask, “Which finger is best to pick at a concrete wall?”, you will get a lot of answers: “Make sure your finger is clean,” “Don’t use your pinky finger—it’s too labor-intensive”, “It’s better to use the fingers of your hand, preferably your right hand, unless, of course, you are ambidextrous” etc

It will take some time. It might even be fun. But that won’t get you one step closer to the bookshelf on the wall.

Do you understand what I’m talking about now?

To create a working extension for LibreOffice, you should forget about XML for a while.

Think about what the future expansion should do and how. Even if the time allotted for the project is only two days, still let the time for thinking take up two-thirds of this entire period.

Now start layout - create a regular document (if the extension is supposed to work with Calc, then let it be a spreadsheet, if the extension is intended for Writer, then make a text document). In this document, create the first module and write in it a lot of comments Rem - who is the author of this program, where and when it was created, what this extension does, how it will need to be used.

Now create dialog boxes, fill them with controls, try to use them, make sure that it is convenient for you, and therefore will be convenient for future users.

Now write the code that will load and display these dialog boxes, which will process control events and receive user input.

Now that you have the ability to enter data for testing, write the code that you intended to write in the first place, something that will do useful work.

When the vast majority of errors have been found and eliminated, move the code to the library in My Macros. After that you will need to change the document to the application… but we can talk about this later, when you have a document with dialogs and code that you can show here and ask “This is where the macro does not work the way I want - how does this can be corrected?”

(then there will only be a few simple steps left until you get the finished product - but that will come later)

1 Like

Alright, I’m going to try more and ask another question. Meanwhile, I simply want to add the progress bar (code+dialog) to the hello world extension:

  1. Replacing the hello world code with the progress bar code.
  2. Adding the progress bar XML dialog to the extension so that the extension recognizes it.

I couldn’t make my extension recognize/find the dialog yet. Anyway, I’ll try more.

Once more

If you throw out this part, then your question is “How can I make a progress bar in a macro?” The answer is given as an example in this thread It shows two options - with a progress bar in the dialog box and in the status bar. Which one would you like to implement in your extension? What kind of progress will this progress bar show? In “Hello, World!” there is nothing to fill this element with.
Sample of ProgressBars.ods (21.1 KB)

1 Like

I’m going to replace the simple “Hello, World!” code with the above code. The above code uses the Wait function and a For to simulate progress. :slightly_smiling_face:

I wish you success! Don’t forget to create Standard.Dialog1 and add ProgressBar1 to it

1 Like

That’s the two things that I have problem with :slightly_smiling_face:

You know, our conversation is reminiscent of dialogue from some sketch show. “I won’t tell you how I came up with this idea and how I got onto the roof of the building with a parachute, how I climbed down to the window using a rope and carefully took out the glass with a diamond glass cutter… In general, when I climbed into the hole, I got stuck. I need help…" - “Why didn’t you just walk through the door and tell the girl at the register “a cheeseburger and a large Coke”? That’s how they usually go to McDonald’s…”

Why did you decide that directly editing the files included in the extension is the correct way to work on the project?

1 Like

I enjoyed the dialog :slightly_smiling_face:

I have no idea. I’m just lost, I guess.

Yes, it looks like it.
So let’s start from the beginning.
Prepare everything you need for the extension in one document and debug it.
Then create a new library in My Macros and transfer the code and dialogs there, make changes to the names of the event handlers (in the document they referred to macro procedures in DOCUMENT, now they need to be changed to APPLICATION)
Then follow the instructions from this file - ExtensionCompiler.ott (220.8 KB)

If something doesn’t go as expected, ask a question here. If everything works out and your extension works the way you intended, mentally or very loudly say three times “Thank you Bernard Marcelly!”

1 Like

Status bar

Eventually, I implemented this approach to take advantage of the document status bar:Apache OpenOffice Community Forum - [Solved] Progress bar in my macro - (View topic)

It was a quick approach. I only had to do this inside my extension code:

Sub MyMainSub()
	doc = ThisComponent

    ' ...

    statusBar = doc.getCurrentController.StatusIndicator ' Reference the active document's status bar
    statusBar.start( "Processing rows ", rowCountApprox ) ' Set the initial text and limit of the status bar
    statusBar.setText( "Processing " + rowCountApprox + " rows") ' Set the status bar text

    MyProcess(statusBar, rowCountApprox)

    statusBar.end() ' Return control to the application

    ' ...

End Sub

Sub MyProcess(statusBar, rowCountApprox)
    For row = 0 To rowCountApprox 
        statusBar.setValue( row ) ' Set the status bar value

        ' ...

    Next row
End Sub