What is the missing link to run these programs together?

What is the missing link to run these programs together?

murmanator
Advocate Advocate
1,037 Views
8 Replies
Message 1 of 9

What is the missing link to run these programs together?

murmanator
Advocate
Advocate

Im missing something here and dont know what it is. In the first program "Travertine" Im trying to string together a few external programs with some prompts in order to go through a sort of checklist approach. Problem Im having is between the TRAVTOP and TRAVCOP programs. If either one of those the are active in the main program is works fine but if BOTH are active it skips the second one and fails on the following line as well. Do I need to add something to the TRAVTOP/TRAVCOP programs or is it something between those lines in the main program? Thank you

 

(defun C:TRAVERTINE () (TRAVERTINE nil))
(DEFUN TRAVERTINE (TYP / pt)
(GV)
(PB)
(GETKWORD "\nEnter Field Label: ")
(C:TPVR-TRV)
(TRAVTOP)
(TRAVCOP)
(GETKWORD "\nBorder: ")
(6X6T)
(SV)
(PRINC)
)

 

(DEFUN TRAVTOP ()
(initget 1)
(IF (NULL TYP)
(PROGN (INITGET "TOP-PATIO NO-TOPPING")
(SETQ TYP (COND ((GETKWORD "\nTOP PATIO? [TOP-PATIO/NO-TOPPING] <TOP-PATIO>: "))
(TOP-PATIO)
)
)
)
)
(COND
((= TYP "TOP-PATIO")
(C:TTOP-TRV)
)
((= TYP "NO-TOPPING")
(C:TNO-TOP)
)
)
; (PRINC)
)

 

(DEFUN TRAVCOP ()
(initget 1)
(IF (NULL TYP)
(PROGN (INITGET "NBN SBN")
(SETQ TYP (COND ((GETKWORD "\nCOPING [NBN/SBN] <NBN>: "))
(NBN)
)
)
)
)
(COND
((= TYP "NBN")
(NBNT)
)
((= TYP "SBN")
(SBNT)
)
)
; (PRINC)
)

0 Likes
Accepted solutions (1)
1,038 Views
8 Replies
Replies (8)
Message 2 of 9

doaiena
Collaborator
Collaborator

This is quite a weird style of coding. At least share with us what the code is supposed to do and where exactly does it fail and with what input.

You start with a function that accepts a variable, but you always supply nil to that function which is a bit weird. Your error most likely comes from the "TOP-PATIO" or "NBN" functions or the following "COND" statements.

Message 3 of 9

murmanator
Advocate
Advocate

Well you're being kind and thank you. Its a weird style of coding because Im not really sure what Im doing with it. That is, Im a beginner programmer. In any case, all of the programs called on in the main program (TPVR-TRV, TRAVTOP, TRAVCOP, and 6x6T) are for adding specific notes or text leaders. The idea is to prompt the user through all the possible notes that are used when the item TRAVERTINE is utilized. Each of the individual programs run fine on their own.

 

In terms of the TRAVTOP and TRAVCOP programs, I have other programs that Ive used as a template for these that use this code, I have just replaced the prompts and what is called by the COND statements.

 

If I run the main program as is, it will go through the TRAVTOP part fine, then skip the TRAVCOP line completely with no error message, then return "Invalid Keyboard Option" on the Border line. If I comment out EITHER the TRAVTOP or TRAVTOP lines, the program runs fine to the end.

 

I have tried several different things in where the nil is and in the same place in TOP and COP programs, but Im afraid this is an area where I lack knowledge in how its supposed to work. 

0 Likes
Message 4 of 9

dlanorh
Advisor
Advisor

TVP is never set as a local variable. It is global and is set in TRAVTOP. When you get to TRAVCOP the (IF (NULL TYP) will always fail as TVP has a value, won't be reset and thus won't meet any of the following conditions.
It needs to be set as a local variable in TRAVTOP and in TRAVCOP

 

(IF (NULL TYP)
  (PROGN 
    (INITGET "TOP-PATIO NO-TOPPING")
    (SETQ TYP (COND (	(GETKWORD "\nTOP PATIO? [TOP-PATIO/NO-TOPPING] <TOP-PATIO>: "))
			(TOP-PATIO)
	            )
	      )
    )
)

What are you trying to achieve with the above? Is this supposed to get what is typed in?

You are asking for a keyword and then ignoring the input and running the function (TOP-PATIO). What happens if someone wants to enter NO-TOPPING?

The same occurs in TRAVCOP function.

 

(DEFUN TRAVERTINE (TYP / pt);TYP is never used in this function, pt is never used in this function
(GV) (PB) (GETKWORD "\nEnter Field Label: ");you are asking for input but the input isn't assigned to a variable and thus never used (C:TPVR-TRV) (TRAVTOP) (TRAVCOP) (GETKWORD "\nBorder: ");you are asking for input but the input isn't assigned to a variable and thus never used (6X6T) (SV) (PRINC) )

See inline comments for this function

I am not one of the robots you're looking for

0 Likes
Message 5 of 9

roland.r71
Collaborator
Collaborator

@dlanorh wrote:

 

(IF (NULL TYP)
  (PROGN 
    (INITGET "TOP-PATIO NO-TOPPING")
    (SETQ TYP (COND (	(GETKWORD "\nTOP PATIO? [TOP-PATIO/NO-TOPPING] <TOP-PATIO>: "))
			(TOP-PATIO)
	            )
	      )
    )
)

What are you trying to achieve with the above? Is this supposed to get what is typed in?

You are asking for a keyword and then ignoring the input and running the function (TOP-PATIO). What happens if someone wants to enter NO-TOPPING?

The same occurs in TRAVCOP function.



Much can be said about this code, but...

This is actually almost correct.

It's a cond that will check for a value, if there is non (user just hits [ENTER]), THEN it calls the function (TOP-PATIO), which by the looks of it should be a string ("TOP-PATIO")

 

As TYP is global, it might be better to use that, so it uses the last choice:

(INITGET "TOP-PATIO NO-TOPPING")
(SETQ TYP 
   (COND 
      ((GETKWORD (STRCAT "\nTOP PATIO? [TOP-PATIO/NO-TOPPING] <" TYP ">: ")))
      (TYP)
   )
)

 

This sets TYP with whatever user chooses (with current value as default), OR its previous value (if GETKWORD returns nil)

 

but then again, TYP should not be global ...

 

edit:

OP, got a stuck CAPS-LOCK key? If not...

You should loosen up on those.

GETKWORD, GETPOINT etc. Actually use CAPS as "shortcuts".

Change your INITGET to: (initget "Top-patio No-topping") and your GETKWORD into: (getkword "\nTop patio? [Top-patio/No-topping] " etc...

This will allow you and your user to type "T" for Top-patio and "N" for No-topping, instead of typing the entire word. You will notice the text is black, excepts for the CAPS, those will be blue (currently its probably all blue)

0 Likes
Message 6 of 9

roland.r71
Collaborator
Collaborator
Accepted solution

@murmanator wrote:

(defun C:TRAVERTINE () (TRAVERTINE nil)) ; what's this for???
(DEFUN TRAVERTINE (TYP / pt) ; TYP is a mandatory argument, but never used... & there's no pt either.
(GV)
(PB)
(GETKWORD "\nEnter Field Label: ") ; this goes nowhere. Return value should go to variable
(C:TPVR-TRV)
(TRAVTOP)
(TRAVCOP)
(GETKWORD "\nBorder: ") ; Same as above
(6X6T)
(SV)
(PRINC)
)

 

(DEFUN TRAVTOP ()
(initget 1) ; what's this for? NOTE: if TYP is NOT null, this will be used for NEXT GETKWORD in your code, NOT the one below. (so it should be AFTER the IF)
(IF (NULL TYP) ; This will always be True, as you force it to be nil with your C:TRAVERTINE function.
(PROGN (INITGET "TOP-PATIO NO-TOPPING") ; ...and if it IS null, you set it again???
(SETQ TYP (COND ((GETKWORD "\nTOP PATIO? [TOP-PATIO/NO-TOPPING] <TOP-PATIO>: ")) ; Check your CAPS-LOCK and get it fixed if stuck!
(TOP-PATIO) ; is this not suposed to be a string?
)
)
)
)
(COND
((= TYP "TOP-PATIO")
(C:TTOP-TRV)
)
((= TYP "NO-TOPPING")
(C:TNO-TOP)
)
)
; (PRINC)
)

 

(DEFUN TRAVCOP ()
(initget 1) ; Same as before, put it AFTER the IF. (well, actually just delete it. its obsolete)
(IF (NULL TYP) ; this will NEVER be true, as it gets set inside TRAVTOP
(PROGN (INITGET "NBN SBN") ; and again, you set the initget here for a second time
(SETQ TYP (COND ((GETKWORD "\nCOPING [NBN/SBN] <NBN>: "))
(NBN)
)
)
)
)
(COND
((= TYP "NBN")
(NBNT)
)
((= TYP "SBN")
(SBNT)
)
)
; (PRINC)
)


If the rest of your code/functions look similar, you've got a lot of work to do...

As they are not here, it's hard to say what should be done with all the missing vars, if they should be local or global etc.

 

If TYP MUST be global (impossible to say right now, but it looks like its not) change it to TYP1 & TYP2 or something for the various functions. OR make it local (in which case you can definately drop the (IF NULL TYP) check, since that will always be True.)

 

edit:

Here's how it should be, somewhat (i just made it work, not optimized) :

I catch the first GETKWORD's inside globals (marked with * for easy recognition) and set TYP as local. As the other functions are not here, i can't say if that will work with those.

AND to use the values for Field label and Border, you will need to use those vars, somewhere.

(defun c:travertine (/)
   (gv)
   (pb)
   (setq *flab (getkword "\nEnter Field Label: "))
   (c:tpvr-trv)
   (travtop)
   (travcop)
   (setq *bordr (getkword "\nBorder: "))
   (6x6t)
   (sv)
   (princ)
)

(defun travtop (/ typ)
   (initget "Top-patio No-topping")
   (setq typ 
      (cond 
         ((getkword "\nTop patio? [Top-patio/No-topping] <Top-patio>: "))
         ("Top-patio")
      )
   )
   (cond
      ((= typ "Top-patio")
         (c:ttop-trv)
      )
      ((= typ "No-topping")
         (c:tno-top)
      )
   )
)

(defun travcop ( / typ)
   (initget "Nbn Sbn")
   (setq typ 
      (cond 
         ((getkword "\nCoping [Nbn/Sbn] <Nbn>: "))
         ("Nbn")
      )
   )
   (cond
      ((= typ "Nbn")
         (nbnt)
      )
      ((= typ "Sbn")
         (sbnt)
      )
   )
)
0 Likes
Message 7 of 9

dlanorh
Advisor
Advisor

@roland.r71 wrote:

Much can be said about this code, but...

This is actually almost correct.

It's a cond that will check for a value, if there is non (user just hits [ENTER]), THEN it calls the function (TOP-PATIO), which by the looks of it should be a string ("TOP-PATIO")

 

I realise that but since the OP hasn't included (TOP-PATIO) and nothing is passed into (TOP-PATIO) it is pure speculation as to how it works without seeing the code. Your guess is probably correct but it won't run in the VLIDE on my system so I can't test it. Robot Sad
Obfuscated code is very difficult to debug if you only have part of the code.

I am not one of the robots you're looking for

0 Likes
Message 8 of 9

murmanator
Advocate
Advocate

Thank you for explaining all this and tolerating my lack of knowledge. The fixed code you posted works great, thank you for doing that! I see I have much to learn and do appreciate all your input.

0 Likes
Message 9 of 9

roland.r71
Collaborator
Collaborator

Happy to help.

We all start with 0 knowledge & learn by making mistakes.

Realy, there is no better teacher as a mistake. Unless you repeat the same mistakes, again and again Smiley Wink

 

Debugging code can be a 'revelation'. Smiley LOL

0 Likes