How to make a pop up list with selected item returned to macro

I want to make a macro that can create a pop-up box with a list of items to choose from, similar to a ‘select’ HTML tag with size = to the number of items. Upon selection of one of the items, that item is returned to the macro for further execution.

How can I create this pop-up box with a macro written in basic?

Only the InputBox exists as a predefined tool in the StarBasic:without any selecting feature.
.
You can create a Form, and you can create (manually or programatically) a Combo Box or a List Box on the Form . Then you can control that Form and the Form Control Elements by your macro.
.
The controlling method depends on which Application you want to use the Form with.
You can store the manually created Form(s) in a Module of the the document or in a myMacros of the LO. The temporarly (programatically) created Forms exist in the Memory only.

Link

Hello, it’s possible to use a dialog with listbox, e.g.

Sub Fill_Listbox
    oSheet = ThisComponent.Sheets.getbyname("Sheet1")
    oRange = oSheet.getCellRangebyName("A2:A16")
    aData = oRange.getdataarray
    DialogLibraries.loadLibrary( "Standard" )
    dlg_Listbox = DialogLibraries.Standard.dlg_Listbox
    odlg_Listbox = CreateUnoDialog( dlg_Listbox )
    oListbox = odlg_Listbox.GetControl("Listbox")
    for i = 0 to uBound(aData)
       sListboxText = aData(i)(0)
       oListbox.addItem (sListboxText, i)
    next i
    if odlg_Listbox.execute then
        print "Success, you selected: " & oListbox.SelectedText
    endif
end sub

here’s a sample file
Dialog_with_Listbox.ods (15.6 KB)

If you have a relatively new version of LO, you can use the ScriptForge PopupMenu service which is explained in detail here:

https://help.libreoffice.org/7.5/en-US/text/sbasic/shared/03/sf_popupmenu.html?DbPAR=BASIC

A snippet of an example from that page is:

 Sub ShowPopup
     GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
     Dim myPopup As Object
     Set myPopup = CreateScriptService("SFWidgets.PopupMenu", , 300, 300)
     myPopup.AddItem("Item ~A")
     myPopup.AddItem("Item ~B")
     vResponse = myPopup.Execute()
     MsgBox("Selected item ID: " & vResponse)
     myPopup.Dispose()
 End Sub

I’ve been using this in a project of my own. It sounds like just the kind of thing you want.