Set listindex to unknown value?

Here is my dilemma.

I have a String property called “DesiredValue” and it could contain any value (from a list of 20 different values).

I need to be able to say:
set myPopupmenu’s listindex to whatever row contains the string DesiredValue.

Hope that made sense :slight_smile:

Put this in a module

Sub SetPMText(extends pm as PopupMenu, assigns s as String) for i as integer = 0 to pm.ListCount-1 if pm.list(i) = s then pm.ListIndex = i exit end next End Sub

Call it by MyPopup.SetPMText = “DesiredValue”

I think this originated from Bob Keeney’s Utility module.

So that code goes in a Method called SetPMText in my main module?

note this only sets ListIndex IF “s” is found, if “s” is NOT found, the listindex remains as it was

That’s fine - s will definitely be there.

Not quite sure if Peter’s code goes in a Method, inside my main module though?

Any “Module”

just paste that code into a module…

Thanks guys - it worked like a charm :slight_smile: