Andrew1979 Posted May 22, 2015 Share Posted May 22, 2015 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 Quote Link to comment Share on other sites More sharing options...
ymg3 Posted May 22, 2015 Share Posted May 22, 2015 Andrew, Either supply a default value in your listbox, or call a popup dcl if the user press ok before giving a value. Go to Lee Mac's page for popup subroutine . http://www.lee-mac.com/popup.html ymg Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 23, 2015 Share Posted May 23, 2015 Use a while to check if a value has been returned else say use (Alert "You must pick something") and then do dcl again. Quote Link to comment Share on other sites More sharing options...
Andrew1979 Posted May 23, 2015 Author Share Posted May 23, 2015 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 23, 2015 Share Posted May 23, 2015 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 Quote Link to comment Share on other sites More sharing options...
Kowal Posted May 26, 2015 Share Posted May 26, 2015 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 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 27, 2015 Share Posted May 27, 2015 (edited) 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 May 28, 2015 by BIGAL Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.