Jump to content

Recommended Posts

Posted (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 by DavidP
Posted

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)
)

 

 

  • Like 1
Posted

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"

 

  • Like 1
Posted
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?

Posted
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")

 

Posted
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.

Posted
2 hours ago, DavidP said:

Great tip as this was my issue.  Thanks Guys.

Just me and your welcome

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...