DavidP Posted March 22, 2022 Share Posted March 22, 2022 (edited) Need help with following code. For some reason when the cond when comparing strings always fail. I'm I doing something wrong. Does the strcat return different datatype? (defun c:foo4 ( / testA TestB ) (setq x "NI") (setq y "T0") (setq z "I") (setq d "_") (setq nLay "Layer not defined, cond failed") (setq testA (strcat x d y d z)) (setq testB "NI_T0_I") (princ (strcat "'" TestA "' vs '" TestB "'")) (if (= TestA TestB) (princ "\nIs A Equal B =Yes") (princ "\nIs A Equal B = NO") ) (cond ((= testA "NI_T0_I" ) (setq nLTs 10) (setq nLIy "I_T0")) ((= testA "NI_T0_R" ) (progn (setq nLTs 10) (setq nLIy "T0-R")) ) ((= testA "NI_T0_C" ) (progn (setq nLTs 10) (setq nLIy "T0-Test")) ) (t nil) ) (princ "\nLayer = ") (princ nLay) (princ) ) Edited March 22, 2022 by DavidP Quote Link to comment Share on other sites More sharing options...
mhupp Posted March 22, 2022 Share Posted March 22, 2022 I'm guessing this is just a test lisp and x y x will be set in some other way? unless the inputs change it will always have the same output. Looking at your code its always going to say "Layer = Layer not defined, cond failed" because you set nLay in the start but then don't redefine it in any of the cond's Some more reading on the topic. (defun c:foo4 ( / x y z d nLay testA TestB nTLs nLIy) ;list variables you are using (setq x "NI") (setq y "T0") (setq z "R") ;I for cond 1, C for cond 3 (setq d "_") (setq testA (strcat x d y d z)) (setq testB "NI_T0_I") (princ (strcat "\n\"" TestA "\" vs \"" TestB "\"")) ; \" to use quotes in lisp (if (= TestA TestB) (princ "\nIs A Equal B =Yes") (princ "\nIs A Equal B = NO") ) (cond ((= testA "NI_T0_I" ) (setq nLTs 10) (setq nLIy "I_T0") (setq nLay "\nCondtion One Met \nLayer is \"I_T0\"") ) ((= testA "NI_T0_R" ) ;don't need (progn (setq nLTs 10) (setq nLIy "T0-R") (setq nLay "\nCondtion Two Met \nLayer is \"T0-R\"") ) ((= testA "NI_T0_C" ) (setq nLTs 10) (setq nLIy "T0-Test") (setq nLay "\nCondtion Three Met \nLayer is \"T0-Test\"") ) (t ;this is a better place to put the fail statment. (setq nLay "Layer Not Defined, All Cond's Failed") ) ) (princ "\nLayer = ") (princ nLay) (princ) ) 1 Quote Link to comment Share on other sites More sharing options...
mhupp Posted March 22, 2022 Share Posted March 22, 2022 You could also use strcase on testA to eliminate any case sensitivity. (setq x "ni") (setq y "T0") (setq z "r") (setq d "_") (setq testA (strcase (strcat x d y d z))) testA = "NI_T0_R" 1 Quote Link to comment Share on other sites More sharing options...
DavidP Posted March 22, 2022 Author Share Posted March 22, 2022 8 minutes ago, mhupp said: I'm guessing this is just a test lisp and x y x will be set in some other way? unless the inputs change it will always have the same output. Looking at your code its always going to say "Layer = Layer not defined, cond failed" because you set nLay in the start but then don't redefine it in any of the cond's Some more reading on the topic. (defun c:foo4 ( / x y z d nLay testA TestB nTLs nLIy) ;list variables you are using (setq x "NI") (setq y "T0") (setq z "R") ;I for cond 1, C for cond 3 (setq d "_") (setq testA (strcat x d y d z)) (setq testB "NI_T0_I") (princ (strcat "\n\"" TestA "\" vs \"" TestB "\"")) ; \" to use quotes in lisp (if (= TestA TestB) (princ "\nIs A Equal B =Yes") (princ "\nIs A Equal B = NO") ) (cond ((= testA "NI_T0_I" ) (setq nLTs 10) (setq nLIy "I_T0") (setq nLay "\nCondtion One Met \nLayer is \"I_T0\"") ) ((= testA "NI_T0_R" ) ;don't need (progn (setq nLTs 10) (setq nLIy "T0-R") (setq nLay "\nCondtion Two Met \nLayer is \"T0-R\"") ) ((= testA "NI_T0_C" ) (setq nLTs 10) (setq nLIy "T0-Test") (setq nLay "\nCondtion Three Met \nLayer is \"T0-Test\"") ) (t ;this is a better place to put the fail statment. (setq nLay "Layer Not Defined, All Cond's Failed") ) ) (princ "\nLayer = ") (princ nLay) (princ) ) Correct this is only for testing... basically I am trying to concatenate a new string based on three user responses... then I want to trap the using Con by evaluation against predefined options. I this case shouldn't the nlay be populated in the first Cond section? Quote Link to comment Share on other sites More sharing options...
mhupp Posted March 22, 2022 Share Posted March 22, 2022 6 minutes ago, DavidP said: I this case shouldn't the nlay be populated in the first Cond section? its in all 4. (setq nLay "\nCondtion One Met \nLayer is \"I_T0\"") (setq nLay "\nCondtion Two Met \nLayer is \"T0-R\"") (setq nLay "\nCondtion Three Met \nLayer is \"T0-Test\"") or (setq nLay "Layer Not Defined, All Cond's Failed") Quote Link to comment Share on other sites More sharing options...
DavidP Posted March 22, 2022 Author Share Posted March 22, 2022 56 minutes ago, mhupp said: You could also use strcase on testA to eliminate any case sensitivity. (setq x "ni") (setq y "T0") (setq z "r") (setq d "_") (setq testA (strcase (strcat x d y d z))) testA = "NI_T0_R" Great tip as this was my issue. Thanks Guys. Quote Link to comment Share on other sites More sharing options...
mhupp Posted March 22, 2022 Share Posted March 22, 2022 2 hours ago, DavidP said: Great tip as this was my issue. Thanks Guys. Just me and your welcome 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.