How do I dynamically change the selection for a list box in a dialog

I have a dialog, LatLong Wizard. Among various boxes is a ListBox, called LatDirBox which has two items: N and S. The Selection is 0, for N. We are collecting ship data and most of our ships are located in the Northern Hemisphere, but we are now working on some ships that are spending much of their time in the Southern hemisphere. It’s not practical to have the users change the LatLong Wizard itself. Our spreadsheets have a Setup Page which allows the user to change various parameters depending on the circumstances at the time. We would like to be able to be able to change the default 0 for the selection to be 1 for South simply by changing a variable on the Setup Page, which is easy for the users.

We have been using the various dialogs for about three years, and we have code for our Event Wizard to dynamically change a subtype depending on the type of event selected by the user, so we are familiar with coding for these dialogs.

I’m aiming for macro code that will set the Selection so it will show S when the dialog is opened. I was aiming for something like:

ArgOut = Dlg.Execute()
Selection = Dlg.getControl(“SelectionBox”)
Selection.Text = “1”

but, needless to say, that doesn’t work.

Please upload your ODF type sample file with the embedded macro code.

If there are only two values, why don’t you replace the listbox with a radio button? (It looks to me like you are trying to find the .SelectedItem property )

Here is the LatLong Dialog. I want to set the default selection with code like:

Sub SetDefaultLatLon

Dim LatDirBox As Object

LatDirBox = Dlg.getControl("LatDirBox")
LatDirBox.Selection = 1

End Sub

which would be called when the LatLong Wizard is called. I have uploaded Untitled2.ods which has the LatLong dialog and the macro that executes it.
Untitled 2.ods (12.9 KB)

Try this

Sub SetDefaultLatLon(selectItem As Integer)
Dim LatDirBox As Object
   	LatDirBox = Dlg.getControl("LatDirBox")
	LatDirBox.selectItemPos(1-selectItem,FALSE)
	LatDirBox.selectItemPos(selectItem,TRUE)
End Sub

and call it as setDefaultLatLon(0) or setDefaultLatLon(1)

(Consider replacing ListBoxes with other controls after all - Untitled 3.ods (15.4 KB))