ADDING LARGE NUMBERS

ADDING LARGE NUMBERS

Anonymous
Not applicable
1,357 Views
2 Replies
Message 1 of 3

ADDING LARGE NUMBERS

Anonymous
Not applicable

Hi, Dear

I am using this program for adding large numbers it is not giving m correct sum while for smaller numbers it is ok, Please any advice.

thanks

 

 

(defun c:Stxt (/ ans flag)
  (setq flag t)
  (setvar "cmdecho" 0)
  (setvar "osmode" 0)
  (setq ht (getint "\nEnter Universal Height"))
 
  (while flag
    (initget "1 2 3 4 5 6 7 8 9 10")
    (setq ans (entsel "\nmake your selection[2/3/4/5/6/7/8/9/10]<exit>:"))
    (cond ((= ans nil)
    (setq flag nil)
    (prompt "\nyou didn't select an object, or you did press spacebar or enter, to exit...")
   )
          ((= 'list (type ans))
    (prompt "\nyou did select an object...")
   )
  ((= "2" ans)
    ;(prompt "\nyou did enter Beta...")
    (setq 1st (atoi (cdr (assoc 1 (entget (car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq addd (+ 1st 2nd))
    (command "text" Pause ht "0" addd "")
     )

          ((= "3" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq addd (+ 1st 2nd 3rd))
    (command "text" Pause ht "0" addd "")
    )

   ((= "4" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq addd (+ 1st 2nd 3rd 4th))
    (command "text" Pause ht "0" addd "")
    )
         ((= "5" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq 5th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fifth Text")))))))
    (setq addd (+ 1st 2nd 3rd 4th 5th))
    (command "text" Pause ht "0" addd "")
    )
         ((= "6" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq 5th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fifth Text")))))))
    (setq 6th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the sixth Text")))))))
    (setq addd (+ 1st 2nd 3rd 4th 5th 6th))
    (command "text" Pause ht "0" addd "")
    )
   ((= "7" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq 5th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fifth Text")))))))
    (setq 6th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the sixth Text")))))))
    (setq 7th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the seventh Text")))))))
    (setq addd (+ 1st 2nd 3rd 4th 5th 6th 7th))
    (command "text" Pause ht "0" addd "")
    )
         ((= "8" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq 5th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fifth Text")))))))
    (setq 6th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the sixth Text")))))))
    (setq 7th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the seventh Text")))))))
    (setq 8th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Eighth Text")))))))
    (setq addd (+ 1st 2nd 3rd 4th 5th 6th 7th 8th))
    (command "text" Pause ht "0" addd "")
    )
         ((= "9" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq 5th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fifth Text")))))))
    (setq 6th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the sixth Text")))))))
    (setq 7th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the seventh Text")))))))
    (setq 8th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Eighth Text")))))))
    (setq 9th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Ninth Text")))))))
    (setq addd (+ 1st 2nd 3rd 4th 5th 6th 7th 8th 9th))
    (command "text" Pause ht "0" addd "")
    )
         ((= "10" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq 5th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fifth Text")))))))
    (setq 6th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the sixth Text")))))))
    (setq 7th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the seventh Text")))))))
    (setq 8th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Eighth Text")))))))
    (setq 9th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Ninth Text")))))))
    (setq 10th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the tenth Text")))))))
    (setq addd (+ 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th))
    (command "text" Pause ht "0" addd "")
  
    )

    );; cond
  );; while
  (princ)
)

 

0 Likes
Accepted solutions (1)
1,358 Views
2 Replies
Replies (2)
Message 2 of 3

phanaem
Collaborator
Collaborator

Replace atoi with atof, then in the text command use (rtos addd 2 0).

0 Likes
Message 3 of 3

DannyNL
Advisor
Advisor
Accepted solution

Looking at your code I'm not sure why you choose to go with COND and select the texts one by one if you are adding them and the order doesn't really matter. Also you have limited the number of texts that can be selected.

 

Maybe you have your reasons why, but if not please check the code below as the end result is the same, but with more freedom and no limitation in selecting your texts.

 

(defun c:Stxt (/ S_Selection S_Total S_Count)
   (setq S_Selection (ssget '((0 . "TEXT"))))
   (if
      S_Selection
      (progn
         (setq S_Total 0)
         (setq S_Count 0)
         (repeat (sslength S_Selection)
            (setq S_Total (+ (atof (vla-get-TextString (vlax-ename->vla-object (ssname S_Selection S_Count)))) S_Total))
            (setq S_Count (1+ S_Count))
         )
         (if
            (/= S_Total 0)
            (command "-TEXT" PAUSE PAUSE "0" (rtos S_Total))
         )
      )
   )
   (princ)
)