sure..in my response to your first post I showed you the following code to test the length of the text string r:
(setq len (strlen r))
(cond
((= 1 len)(setq r (strcat "000" r))
((= 2 len)(setq r (strcat "00" r))
((= 3 len)(setq r (strcat "0" r))
(t (princ"\nNumber is greater than 4 digits"))
)
In that case r represented the value of the text string you wanted to use.
Now you have two text strings you need to test: f and stn:
(cons 1 F ".ROOM" stn) ; but this is incorrectly coded because again like before you need to convert stn from an integer to a string using function itoa and then connect the text strings together using function strcat:
(cons 1 (strcat F ".ROOM" (itoa stn)))
Also, this time you only need to test if the length of the text string is 1 character and then add the zero in front.
So you can either run this revised code 2x like this:
(setq len (strlen F))
(if(= 1 len)(setq F (strcat "0" F))) ; adds 0 in front only if character length is 1 which takes care of F
(setq G (itoa stn)) ; save the converted # to string as G
(setq len (strlen G)) ; get the length
(if(= 1 len)(setq G (strcat "0" G))) ; adds 0 in front only if character length is 1 which takes care of G
Now your entmake text string code should look like this:
(cons 1 (strcat F ".ROOM" G))
Now another more efficient way is to create a sub routine or another function that you will run like the above more than once that I'm calling chk_str. This function will pass the text string str as the argument to test and return text string with the added zero if needed:
(defun chk_str (str / len newstr)
(setq len (strlen str))
(if(= 1 len)
(setq newstr (strcat "0" str)) ; adds 0 in front only if character length is 1
(setq newstr str) ; no changes needed
)
newstr ; return
) ; defun
This time your entmake text string code would look like this:
(cons 1 (strcat (chk_str F) ".ROOM" (chk_str (itoa stn))))
putting it all together the updated code will look like this (not tested):
(defun c:SVT (/ chk_str F p stn) ; localize functions & symbols
; chk_str function passes the text string str as the argument to test and
; return text string with the added zero if needed
(defun chk_str (str / len newstr)
(setq len (strlen str))
(if(= 1 len)
(setq newstr (strcat "0" str)) ; adds 0 in front only if character length is 1
(setq newstr str) ; no changes needed
)
newstr ; return
) ; defun
(setq F (getstring "\nEnter floor number: "))
(setq stn (getint "Enter starting number: "))
(while (setq p (getpoint "\n Pick to insert text"))
(entmake
(list
(cons 0 "text")
(cons 10 p)
(cons 40 7)
(cons 50 0.0)
(cons 1 (strcat (chk_str F) ".ROOM" (chk_str (itoa stn)))) ; revised code
) ; list
) ; entmake
(setq stn (+ stn 1))
) ; while
(princ)
) ; defun