Jump to content

DCL check for selection


Andrew1979

Recommended Posts

I am trying to work out how to check if the user has selected something on a drop down list.

 

I want to send an alert in some kind of loop to let the user know they must select something on the list.

 

How do I do that?

 

Thanks

Link to comment
Share on other sites

Thanks ymg3 for the link to the code, will look at that now.

BIGAL, I tried a while loop, I think I wrote it wrong as i got stuck in an infinite loops showing an alert box with no way to close it. Maybe using the while loop with the code in the link posted above may be the way to do it.

Link to comment
Share on other sites

When you populate a DCL popup_list with a set of selectable values (i.e. using start_list/add_list/end_list), the popup_list will automatically display the first of the available items, hence, an item will always be selected as the user can only change this initial item to another item in the list.

 

Observe this behaviour in the following example:

(defun c:popupexample ( / *error* dch dcl des )

   (defun *error* ( msg )
       (if (< 0 dch)(unload_dialog dch))
       (if (= 'file (type des)) (close des))
       (if (and dcl (findfile dcl)) (vl-file-delete dcl))
       (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )

   (if
       (and
           (setq dcl (vl-filename-mktemp nil nil ".dcl"))
           (setq des (open dcl "w"))
           (write-line "popuptest : dialog { key = \"dcl\"; : popup_list { key = \"lst\"; width = 30; } ok_only; }" des)
           (not (setq des (close des)))
           (< 0 (setq dch (load_dialog dcl)))
           (new_dialog "popuptest" dch)
       )
       (progn
           (set_tile "dcl" "Popup List Example")
           (   (lambda ( / n )
                   (start_list "lst")
                   (setq n 0)
                   (repeat 10 (add_list (strcat "Item " (itoa (setq n (1+ n))))))
                   (end_list)
               )
           )
           (start_dialog)
       )
   )
   (*error* nil)
   (princ)
)

@ymg, thank you for the recommendation :thumbsup:

Link to comment
Share on other sites

Lee, your code is very helpful as a basis for other programs. You could change it to select "Item" (string) to insert a variable actual value from the list.

Is a sample list of any length:

'((„Item1” 1.0) („Item2” 2.0) („Item3” 3.0) („Item4” 4.0) („Item5” 5.0))

For example, I choose Item4 from the popup gets a variable with a value of 4.0

Link to comment
Share on other sites

You are on the right track you can have lists of 2 items you will though probably have to make a 2nd list which is the first item and this is used in the DCL which returns its position and then set your variable to the second item in the 1st list.

 

In your example you want 3 returned which is 3rd sub list ("Item4" 4) then pull out 2nd item in list, you can use a nested nth method to do this.

 

(setq val (nth 1 (nth (- x 1) 1stlst))))

Edited by BIGAL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...