Retreiving values from listboxes in LotusScript

I have a Dialog Box (a form with a layout region on it) which has on it a listbox. This listbox is populated in LotusScript using an array of strings and the AppendItemValue method of NotesItem, code looks like this:

If events.count=0 Then 'Only carry on if there are some event docs to process!

	Messagebox "No events found for this person", 0+48, "No events"

Else

	'Create the dummy document 

	Set listdoc = currentdb.CreateDocument

	

	For x = 1 To events.count

		'Redimension dynamic array to allow for new entry to be added

		Redim Preserve listentries(x)

		

		'Add the required details to the string. Prefix each entry with a number for indexing

		Set evtDoc = events.GetNthDocument(x)

		listentries(x-1) = Str(x) + ". " + evtdoc.evtOrder(0) + "  (commencing on " + Str(evtDoc.evtSentDate(0)) + ")"

	Next

	

	'set up the notesitem to represent the list of events

	Set listitem = listdoc.AppendItemValue("lstEvents", listentries)

	

	flag = ws.DialogBox( "dlgEventList" , True , True  , False  , False , False , False , "Events" , listdoc)

	

	Messagebox "need this here to inspect variables",0,""

End If

This creates an array of strings, each prefixed with a value (x) which is increased for each entry.

My problem is, I can’t figure out how to get at the item in the list that the user has selected. The list renders fine, but I can’t find the value selected.

The really weird bit is that it works fine if I use Radio buttons, but will not work for either a listbox or a combobox. I really don’t want to use radio buttons in case the list is longer than the layout allows for…

Anyone any ideas?

Simon

Subject: Retreiving values from listboxes in LotusScript

Funny thing, never noticed the behaviour for radion buttons before. What you need to do is to rename the field in the dialogbox, not in the code. Change the name to Selected and then retrieve the value with listdoc.Selected(0). Don’t forget that you need to have set choices to “Use formula for choices” on the second tab for field properties and set the forumla to lstEvents.

One other thing. Watch out for AppendItemValue

“Note In general, ReplaceItemValue is favored over AppendItemValue. If an item of the same name already exists in a document, AppendItemValue creates a second item of the same name, and the duplicate items are not accessible except through a work-around.”

Subject: Retreiving values from listboxes in LotusScript

What does this return? (place at end of script)

Dim userSelection as NotesItem

Set userSelection = listdoc.GetFirstItem( “lstEvents” )

Print userSelection.Text