scremin Posted June 2, 2013 Posted June 2, 2013 Hello guys, Here I am again in need of some help. My last routine obligated me to start learning some DCL and I a problem has just turned out to me. I have a couple of EditBoxes and I want to avoid the user to insert letters in it. It seems to be kind of easy, but after a hundred of attempts nothing was achieved and I am here looking for some help. How can I "lock" a EditBox to receive only numerical input? Quote
pBe Posted June 2, 2013 Posted June 2, 2013 Hello guys,It seems to be kind of easy, but after a hundred of attempts nothing was achieved and I am here looking for some help. It is. look into errtile function. How can I "lock" a EditBox to receive only numerical input? errtile example linky Replace the validate sub to this (defun validate () (if (not (numberp (read (get_tile "ValidNumber")))) (progn (set_tile "error" (strcat "Only Accepts Numeric Value")) (mode_tile "ValidNumber" 2)) (done_dialog) ) ) Help is here. Now all you had to do is figure out the rest HTH Quote
Tharwat Posted June 2, 2013 Posted June 2, 2013 Consider this just as an example . Dcl codes ... Test : dialog { label = "Just an example"; : boxed_column { : row { : text { label = "Enter First Number : "; alignment = left; } : edit_box { key = "e1"; alignment = right; fixed_width = true ; } } : row { : text { label = "Enter Second Number : " ; alignment = left; } : edit_box { key = "e2"; fixed_width = true ; } } } : spacer { height = 0.25; } : row { alignment = centered ; : button {label = " Okay "; key = "accept"; is_default = true; } : button {label = " Cancel "; key = "cancel"; is_default = false; } } } The lisp codes ... (defun c:Test (/ *error* id v1 v2) (defun *error* (x) (princ "\n*Cancel*")) (setq id (load_dialog "Test.dcl")) (if (not (new_dialog "Test" id)) (progn (alert " Error in loading the dialog (Test.dcl) ") (exit) ) ) (action_tile "accept" "(setq v1 (get_tile \"e1\") v2 (get_tile \"e2\")) (done_dialog)" ) (action_tile "cancel" "(done_dialog)") (start_dialog) (unload_dialog id) (if (or v1 v2) (cond ((and (not (numberp (read v1))) (not (numberp (read v2)))) (progn (alert "The two Inputs are not NUMBERS !!") (C:TEST)) ) ((and v1 (not (numberp (read v1)))) (progn (alert "The two Value in Edit Box-1 is not NUMBER !!") (C:TEST) ) ) ((and v2 (not (numberp (read v2)))) (progn (alert "The two Value in Edit Box-2 is not NUMBER !!") (C:TEST) ) ) (t (princ (strcat "\n Your Input values are ... < " v1 " > and < " v2 " > " ) ) ) ) ) (princ) ) Quote
fixo Posted June 2, 2013 Posted June 2, 2013 Hello guys, Here I am again in need of some help. My last routine obligated me to start learning some DCL and I a problem has just turned out to me. I have a couple of EditBoxes and I want to avoid the user to insert letters in it. It seems to be kind of easy, but after a hundred of attempts nothing was achieved and I am here looking for some help. How can I "lock" a EditBox to receive only numerical input? You can also use the callback function to get a numerical result of textbox input and avoid to input the letters and comma, see quick example ;; digit input textbox example ;; (defun C:DRTL (/ box_callback dcl_id text pick) ;; call back helper (defun box_callback(text act / input) (if (= act 2) (if (not (numberp (read (setq input (get_tile "txt"))))) ;| ;;;could use as well: (not (vl-some 'not (mapcar '(lambda(x)(member x (vl-string->list "0123456789.")))(vl-string->list input) )))|; (progn (set_tile "txt" "Put digits and dot only" ) (mode_tile "txt" 2) ) (set_tile "txt" input ))) ) (setvar "CMDECHO" 0) (setq dcl_id (load_dialog "DRTL.dcl")) (if (not (new_dialog "DRTL" dcl_id)) (exit)) (action_tile "txt" "(box_callback $value $reason)" ) (action_tile "accept" (strcat "(progn " "(setq result (get_tile \"txt\"))" "(done_dialog 1))")) (action_tile "cancel" "(done_dialog 2)") (setq pick (start_dialog)) (unload_dialog dcl_id) (if (= pick 1) (alert (strcat "You entered: " result))) (setvar "CMDECHO" 1) (princ) ) DCL //dcl_settings : default_dcl_settings { audit_level = 3; }// might be commented before to get it to work DRTL : dialog { label = "Enter numeric value:"; :row { fixed_width = true; : boxed_column { label = "--- Allow input the digits an dot only ---"; fixed_width = true; width=36; : edit_box { key = "txt"; initial_focus="1"; edit_width =36; } spacer; } } ok_cancel; } Quote
pBe Posted June 2, 2013 Posted June 2, 2013 You can also use the callback function to get a numerical result of textbox inputand avoid to input the letters and comma, see quick example Nice one my friend. Here;s one for multiple edit box: LSP: (defun C:demo (/ dcl_id v) (setq dcl_id (load_dialog "demorerrortest.dcl")) (if (not (new_dialog "ErrorTest" dcl_id)) (exit) ) (mode_tile "Number1" 2) (action_tile "accept" "(setq v (validate))") (action_tile "cancel" "(done_dialog 0)") (start_dialog) (unload_dialog dcl_id) (print v)(princ) ) (defun validate ( / vals stp) (if (not (vl-every '(lambda (v) (if (numberp (setq val (read (get_tile v)))) (setq vals (cons val vals)) (setq stp v x nil))) '("Number1" "Number2" "Number3"))) (progn (set_tile "error" (strcat "Only Accepts Numeric Value")) (mode_tile stp 2)) (progn (done_dialog 1)(reverse vals)) ) ) DCL ErrorTest : dialog {label = "Numbers only Demo"; : boxed_column { : text { label = "Enter Numerical Values"; alignment = centered;} : edit_box { key = "Number1"; label=" Edit Box 1";} : edit_box { key = "Number2"; label=" Edit Box 2";} : edit_box { key = "Number3"; label=" Edit Box 3";} spacer ; : row { alignment = centered; : button { key = "accept"; label = "Accept"; is_default = true; } : button { key = "cancel"; label = "cancel"; } } : errtile {alignment = centered;} } } HTH Quote
scremin Posted June 2, 2013 Author Posted June 2, 2013 It is. look into errtile function. errtile example linky Replace the validate sub to this (defun validate () (if (not (numberp (read (get_tile "ValidNumber")))) (progn (set_tile "error" (strcat "Only Accepts Numeric Value")) (mode_tile "ValidNumber" 2)) (done_dialog) ) ) Help is here. Now all you had to do is figure out the rest HTH Thanks pBe, Tharwat and Fixo for the quick replies. I implemented the use of (numberp) function which one I wasn't aware of and it worked. (defun val1-p () (if [b](or (not (numberp (read (get_tile "text_dcl")))) (<= (read (get_tile "text_dcl")) 0))[/b] (progn (set_tile "error" "Text Height invalid!") (mode_tile "text_dcl" 2) );progn (progn (if (< (read (get_tile "offset_dcl")) 0) (progn (set_tile "error" "Text Offset invalid!") (mode_tile "offset_dcl" 2) );progn (progn (done_dialog) );progn ))) );defun (or (not (numberp (read (get_tile "text_dcl")))) (<= (read (get_tile "text_dcl")) 0)) Using this I can avoid negative numbers, zero and letter input. Quote
pBe Posted June 2, 2013 Posted June 2, 2013 Consider this just as an example . NOTE: No need for (progn .. in condition statement... Quote
Tharwat Posted June 2, 2013 Posted June 2, 2013 NOTE:No need for (progn .. in condition statement... Correct , Thank you pBe Quote
DaveC Posted January 24, 2017 Posted January 24, 2017 Hello everybody: i need some help, please.. i have a "Edit Box" where I get the project number (automatic) from the CADD files the user try to open it, but sometimes the user need to input the project number, and I need to make sure is not a consecutive or similar repetitive numbers as sample 123456789, 0000000, 11111 etc. this is what I have in the LISP file... (if (numberp (read (get_tile "rd_PN"))) (progn (setq v1 (get_tile "rd_PN")) (done_dialog) ) (progn (alert "Please NUMBERS ONLY..!!") (mode_tile "rd_PN" 3) ) ) and in the DCL file... : edit_box { alignment = left; key = "rd_PN"; edit_width = 10; allow_accept = true; } somebody have an idea how to accomplish this....? Thank in advance, for your help... DC select Quote
Tharwat Posted January 24, 2017 Posted January 24, 2017 Test the following for your reference: (< 1 2 3 4) (= 1 1 1 1) Quote
Tharwat Posted January 24, 2017 Posted January 24, 2017 Sorry, it must be complete as the following: (defun deal (str opr / new rtn) (setq new "") (if (vl-every '(lambda (i) (numberp (read (chr i)))) (vl-string->list str) ) (while (and str (/= str "")) (setq new (strcat new (substr str 1 1) " ") str (substr str 2) ) ) ) (and (/= new "") (setq rtn (opr (read (strcat "(" new ")")))) ) rtn ) Usage of the code: Is equal: (deal "1234567" =) Or is Smaller than: (deal "1234567" <) Quote
Grrr Posted January 24, 2017 Posted January 24, 2017 @Tharwat: _$ (deal "-1234567" =) nil _$ (deal "12.34567" =) Error: misplaced dot on input _1$ This thread has some helpful material (reply #2 by marko_ribar). Quote
Tharwat Posted January 24, 2017 Posted January 24, 2017 but sometimes the user need to input the project number, and I need to make sure is not a consecutive or similar repetitive numbers as sample 123456789, 0000000, 11111 etc. @Tharwat: _$ (deal "-1234567" =) nil _$ (deal "12.34567" =) Error: misplaced dot on input _1$ @Grrr, you need to read what DaveC is asking for and what is their case as they have described it above. Quote
Grrr Posted January 24, 2017 Posted January 24, 2017 @Grrr, you need to read what DaveC is asking for and what is their case as they have described it above. Oh, sorry about that! Quote
Roy_043 Posted January 24, 2017 Posted January 24, 2017 In DaveC's shoes I would compare the user input against a list of actual project numbers. @Tharwat: You idea can be shortened to: (defun TestString (str opr) (and (not (wcmatch str "*[~0-9]*")) (apply opr (vl-string->list str)) ) ) Quote
Roy_043 Posted January 24, 2017 Posted January 24, 2017 Note: The functions are not checking if the digits are in sequence: (deal "1234" <) => T (deal "1489" <) => T Quote
Lee Mac Posted January 24, 2017 Posted January 24, 2017 More clarity is required on what constitutes a valid input - this may be too strict: (defun validate ( str ) (and (wcmatch str "~*[~0-9]*") ((lambda ( lst ) (vl-some '(lambda ( a b ) (< 1 (abs (- a b)))) lst (cdr lst))) (vl-string->list str)) ) ) Quote
Tharwat Posted January 24, 2017 Posted January 24, 2017 Note: The functions are not checking if the digits are in sequence: (deal "1234" <) => T (deal "1489" <) => T As well as yours. _$ (TestString "1489" '<) T Quote
DaveC Posted January 24, 2017 Posted January 24, 2017 Thank you Tharwat, that work well.... So I will create a COND statements for the different options... Thank a lot again... Quote
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.