In general, sub-routines look like this:
(defun :subroutine1 (argument1 argument2 / var-localized1 var-localized2)
...
(setq var-localized somefunctions...)
...
var-localized ;; - very last statement became a value of the whole :subroutine1
)
- you should always pass values thru arguments and the value of the subfunction only (last statement), do not use any global variables.
My example:
(defun :GetBlockAttValue (blk att / etd val)
(while (and (setq blk (entnext blk))
(/= "SEQEND" (cdr (assoc 0 (setq etd (entget blk))))))
(and (= (cdr (assoc 0 etd)) "ATTRIB")
(= (strcase (cdr (assoc 2 etd))) (strcase att))
(setq val (cdr (assoc 1 etd)))))
val)
blk and att are arguments (values - in), no need to localize them.
val became the value of the whole function, in main program you should use this:
(setq ValueOfAtt (:GetBlockAttValue (car (entsel) "ADR"))
If you need to get out of you sub more values then on, use list! Then last statement would be (list val1 val2).
So your routine:
(defun C:adress_plushundra ( / :GetBlockAttValue :WriteBlockAttValue blk-in att-adr-val blk-out) ; subroutines may be localized as well
(while (and (setq blk-in (car (entsel "\nChoose block to copy:")))
(princ (strcat "\nADR value: " (setq att-adr-val (:GetBlockAttValue blk-in "ADR"))))
(setq blk-out (car (entsel "\nChoose block to paste new number:")))
)
(:WriteBlockAttValue blk-out "SADR" att-adr-val))
(princ)
)
(defun :GetBlockAttValue (blk att / etd val)
...
val
)
(defun :WriteBlockAttValue (blk att val / etd)
...
;val - no need for this
)