# XPCE, how to get value from multiple\_selection?

**URL:** https://swi-prolog.discourse.group/t/xpce-how-to-get-value-from-multiple-selection/7381
**Category:** Help!
**Tags:** xpce
**Created:** [April 17, 2024, 2:45pm UTC](https://swi-prolog.discourse.group/t/xpce-how-to-get-value-from-multiple-selection/7381 "2024-04-17T14:45:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![esfort](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@esfort](https://swi-prolog.discourse.group/u/esfort)
#### Post date: [April 17, 2024, 2:45pm UTC](https://swi-prolog.discourse.group/t/xpce-how-to-get-value-from-multiple-selection/7381/1 "2024-04-17T14:45:15Z")

</div>

Hello everyone, I have a problem, if you can help me, I will be very glad.

I’m using: SWI-Prolog version 9.0.4

**I need to implement a multi-selection, but I can’t extract the values of this selection.**  
I managed to implement a single choice, it looks like this:

```prolog
send(W,append,new(S,menu('Your choice:'))),
send_list(S,append, [Answ_list]),
get(S?selection, selection, Answer),

```

As for the multi-selection:

```prolog
:- use_module(library(pce)).

create_multi_select :-
    new(Dialog, dialog('Multi-Selection Example')),
    new(Multiselect, menu),
    send_list(Multiselect, append, ['Option 1', 'Option 2', 'Option 3', 'Option 4']),
    send(Multiselect, multiple_selection, @on),
    send(Dialog, append, Multiselect),
    send(Dialog, append, button('Submit', message(@prolog, show_selected, Multiselect))),
    send(Dialog, open).

show_selected(Multiselect) :-
    get(Multiselect,selection,Selections), 
    write(Selections).

```

**But all I get is @xxxxxxxxxxxx**  
**How can I read the “contents” of the selected responses?**

---

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [April 18, 2024, 3:56pm UTC](https://swi-prolog.discourse.group/t/xpce-how-to-get-value-from-multiple-selection/7381/2 "2024-04-18T15:56:29Z")

</div>

> [@esfort](#):
>
> **But all I get is @xxxxxxxxxxxx**  
> **How can I read the “contents” of the selected responses?**

I guess the @xxx is a `chain` (xpce list). Use chain\_list/2 to convert it to a Prolog list.

---

<div class="post-metadata">

### Author: ![esfort](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@esfort](https://swi-prolog.discourse.group/u/esfort)
#### Post date: [April 19, 2024, 11:19am UTC](https://swi-prolog.discourse.group/t/xpce-how-to-get-value-from-multiple-selection/7381/3 "2024-04-19T11:19:57Z")

</div>

Thanks, it really works for this example and I can get the selected values in the form of [Option 1, Option3].

But when it comes to my expert system, I use **get(S,selection,Selection)** to get a list of selected answer options in the form of **@xxx** , using **chain\_list(Selections,X)** I get: **[@xxx, @xxx, @xxx]**.  
In order to extract the value of the selected answer, I tried **nth0(0,X,First), chain(First,Contents)**, but it doesn’t work. Can you help me with this, please?

---

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [April 19, 2024, 3:55pm UTC](https://swi-prolog.discourse.group/t/xpce-how-to-get-value-from-multiple-selection/7381/4 "2024-04-19T15:55:22Z")

</div>

If you use print/1 rather than write/1 it should print something like @xxx/string, meaning @xxx is an instance of class `string`. Now use `?- manpce(string).` to get docs. Its long ago, but I think get(@xxxx, name, Name) should get a Prolog atom that reflects the string.

There is some old documentation. I forgot where, but Google may find it. Basically xpce should be considered a sleeping library though. It may be revived, but more likely it will eventually die.

---

<div class="post-metadata">

### Author: ![esfort](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@esfort](https://swi-prolog.discourse.group/u/esfort)
#### Post date: [April 21, 2024, 5:54pm UTC](https://swi-prolog.discourse.group/t/xpce-how-to-get-value-from-multiple-selection/7381/5 "2024-04-21T17:54:50Z")

</div>

I was able to extract the value of a variable from a multi-selection by extracting each item from the list and then **get(S,value,Answer)**.

It’s sad about the fate of the xpce library. But I was able to make a window interface for my expert system, and with your help it became even better.  
**Thanks for your answers!**
