How to pause a LO Basic macro so that a user can make a listbox selection that will be assigned to a string variable and then resume the macro

I need to pause my macro to allow the user to select a text string from a pre-existing listbox named “Macrotext”, then assign the chosen string to a variable “oField2”, and resume the macro. I’m not quite sure how to go about this. I’ve explored the msgbox and Input Box functions, but I don’t see a way to allow the user to select from a listbox instead of the buttons on a msgbox or text from an input Box. Below is the code I’m working with. The area in the code marked “NOT SURE WHAT TO DO HERE” is the area of interest. Here I started to use a msgbox to pause the macro, and assign the result of the msgbox function to a variable for use in an IF THEN statement, but didn’t know where to go from there.

Thanks in advance for any input.

REM  *****  BASIC  *****
Sub ShowText(answer)
	Dim oForm As Object
	Dim oSubForm As Object
	Dim oSubForm2 As Object
	Dim oField As Object	
	Dim oField2 As Object
	Dim string1 As String
	Dim string2 AS String
	Dim string3 As String
	Dim Occur AS String
	Dim Return_value As String
		
'Get the forms
	oForm = ThisComponent.Drawpage.Forms.getByName("Patient Data") 'Get Form
	oSubForm = oForm.getByName("Chief Complaint") 'Get Subform
    oSubForm2 = oSubForm.getByName("Diagnoses") 'Get Subform2 
	
'Get fields	
'Get "A_P" textbox where SOAP note contents will be displayed and "Macrotext" listbox
	oField = oSubForm.getByName("A_P") 
    oSubForm2.getByName("Macrotext")

'Need to pause here to get user input from "Macrotext" list box selection
    Return_value = MsgBox("Please choose macro text from dropdown list", OKOnly,)
	If Return_value = "1" then <NOT SURE WHAT TO DO HERE> 'user pushed "OK" button
	
'Get listbox "Macrotext" contents to replace "LOCATION" via SelectedValue function below
	oField2 = oSubForm2.getByName("Macrotext")
	
' Insert text to display in "A_P" textbox
	oField.text = oField.text + Answer 

'Search contents of "A_P" textbox after insertion for occurance of "LOCATION" and replace with selection from "Macrotext" listbox	
	string1 = oField.text 'string to be searched in Replace procedure
	string2 = "LOCATION" 'string to be searched for in Replace procedure
	string3 = oField2.SelectedValue 'Get "Macrotext" listbox selection for replacement string
	
	Occur = Replace(string1, string2,string3)
	oField.text = Occur    	
	
		End Sub

Typically when interacting with a user, a dialog is used. You can find a good starting place for this in OOME (Open Office Macros Explained) Chapter 18. You can get the PDF version here .

Thanks Ratfinder,

I’ll digest that chapter and post my solution here assuming I can get things sorted out.

Yes, I definately needed a dialog. In particular, I needed a non-modal dialoge. If you’re not familiar with this term, it means a dialog that allows the user to interact with the underying application (in my case Base) while the dialoge is on the screen. I was using the dialog to pause the macro so the user could pick a selection from a Base listbox and then use that selection for futher processing in the macro. Typically, a dialog is modal, so knowing how to make one that’s not modal is a handy little skill to have. Fortunately, a method of doing this has already been posted on this forum. See this link:

I was able to basically drop this code in my macro, and get it to work with minimal modification. The main issue was just gettiing it to work with my particular macro/dialog library structure. If you’re not very experienced with LO VBA (like me) it’s also good to know that you also have to declare the Global variables at the beginning of your macro before any sub routines. He only has one in his code (global Continue As Boolean). The only other thing I had to do is copy the dialog from his sample code and place it in the same document (in the standard macro library for the document, not the actual document) that contained the macro I was working on. Easy Peasy.

Thanks to pierre-yves samyn for posting his sample code.
docbda

I forgot to add that you need to set his code up as a sub (basically, just cut and paste it into your macro). Then, you can just call it whenever you need it. Also, it’s good to know that after you call the dialog, your code will resume at the point immediately following the point from which it was called. I thought that I had set up an event macro connected to the dialog box to control the flow of the macro. You can, but it defaults to the next line of your code that called the dialog.

Glad you solved your problem. FYI - you didn’t need a modeless dialog if you just wanted the user to make a listbox selection. This could be done right from the dialog. The only modeless dialog I’ve used is to display a table of average balances so the user could make future entries based upon these past averages. And yes, as a not so commonly discussed control, you can create a grid (not a table control) with columns, titles and rows in a dialog.