xspacex Posted November 2, 2009 Posted November 2, 2009 Hello Everyone, I think I have a simple question, so hopefully I will find my answer… When I use this code, everything works fine (while (/= dst1 "400") (setq dst1 (getstring T "\nEnter Width (400,200): "))) However, when I try to use “or”, I can’t get it to work (while (or (/= dst1 "400")(/= dst1 "200")) (setq dst1 (getstring T "\nEnter Width (400,200): "))) Thanks in advance! Quote
alanjt Posted November 2, 2009 Posted November 2, 2009 If dst1 doesn't equal 400 or 200 in the or statement, it will return nil. Thus, terminating while. Try and instead of or. Quote
flowerrobot Posted November 2, 2009 Posted November 2, 2009 If your going to use the getstring function, why not go the route of (initget 7 "200 400") (setq dst1 (getstring T "\nEnter Width (400,200): ")) But to answer your question try, (while (not (or [color=black][font=Verdana](= dst1 "200")[/font][/color][color=black][font=Verdana](= dst1 "400")[/font][/color])).... Other wise i think you would need an "and" instead of an "or" statement. Aswell if my memory severs me correct "/=" can cause a probblem now and then, and better useing "not"...Mind you im quiet sinile in my younge age. Or (while (not (member dst1 '("200" "400"))).... Quote
alanjt Posted November 2, 2009 Posted November 2, 2009 FlowerRobot, initget doesn't work with getstring. Quote
xspacex Posted November 2, 2009 Author Posted November 2, 2009 Thanks for the responses. I didn’t have success using (initget 7 "400 200"), because if I enter a value other than 400 & 200, the program will continue. However, using “and” and using (not (or works for the most part, but the problem I am having now, is that if I enter 400 as the width, and then repeat the command a minute later, it will skip the while loop (which is the part that asks to enter the distance) and move to the next step. It seems like it is remembering the distance input the first time the command is used... Any reasons why? Thanks again Quote
alanjt Posted November 2, 2009 Posted November 2, 2009 Thanks for the responses.I didn’t have success using (initget 7 "400 200"), because if I enter a value other than 400 & 200, the program will continue. However, using “and” and using (not (or works for the most part, but the problem I am having now, is that if I enter 400 as the width, and then repeat the command a minute later, it will skip the while loop (which is the part that asks to enter the distance) and move to the next step. It seems like it is remembering the distance input the first time the command is used... Any reasons why? Thanks again You are not localizing your variables. It's hard to guess w/o seeing the code. Why not use getreal, getdist or getint to eliminate the user entering alpha characters? You can always convert it to a string if/when you need to. Quote
xspacex Posted November 2, 2009 Author Posted November 2, 2009 Once this code is done, i will add it to another code we have in the office, which draws radiator lines. This part will help offset the lines... (defun c:test (/ en1 pt1 and) (setvar "cmdecho" 0) (while (not (or (= dst1 "400")(= dst1 "200"))) (setq dst1 (getstring T "\nEnter Width (400,200): ")) ) (setq en1 (entlast)) (setq pt1 (getpoint "\nSpecify Offset Side:")) (if (= dst1 "400") (progn (command "._offset" 400 en1 "_non" pt1 "") )) (if (= dst1 "200") (progn (command "._offset" 200 en1 "_non" pt1 "") )) (setvar "cmdecho" 1) (princ) ) Quote
xspacex Posted November 2, 2009 Author Posted November 2, 2009 You are not localizing your variables. I had to add dst1 and i had to remove and in my localized variables Thanks everyone Quote
alanjt Posted November 2, 2009 Posted November 2, 2009 Try something like this: (defun c:test (/ en1 dst1 pt1) (setvar "cmdecho" 0) (and (setq en1 (entlast)) (while (not (member dst1 '(200 400))) (setq dst1 (getreal "\nEnter Width [200/400]: ")) ) ;_ while (setq pt1 (getpoint "\nSpecify Offset Side: ")) (command "_.offset" dst1 en1 "_non" pt1 "") ) ;_ and (setvar "cmdecho" 1) (princ) ) ;_ defun Plus, you can select the 200 or 400 if dynamic mode is on, or a right-click. Quote
flowerrobot Posted November 3, 2009 Posted November 3, 2009 FlowerRobot, initget doesn't work with getstring. Whoops was thinking of getkword, but wrote getstring, Was drinking my morning coffeee so you know how it is... Quote
alanjt Posted November 3, 2009 Posted November 3, 2009 Whoops was thinking of getkword, but wrote getstring, Was drinking my morning coffeee so you know how it is... For me it would have been a jittery getstrrrriiiiing. 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.