How to change " * " to *

Discussion in 'AutoCAD' started by Adesu, Mar 15, 2005.

  1. Adesu

    Adesu Guest

    (setq aa 1)
    (setq bb 2)
    (setq cc 3)
    (prompt "Select Add Subtracts Divides Multiply")
    (initget " A S D M ")
    (setq opt (getkword "\nCHOOSE ONES <A/S/D/M>: "))
    (cond ((eq opt "A")(setq opt (chr 43)))
    ((eq opt "S")(setq opt (chr 45)))
    ((eq opt "D")(setq opt (chr 47)))
    ((eq opt "M")(setq opt (chr 42)))
    )
    (setq total (opt aa bb cc))
    (princ total)

    The problem is

    _$ (setq total (opt aa bb cc))
    ; error: bad function: "*"
     
    Adesu, Mar 15, 2005
    #1
  2. Adesu

    Jeff Mishler Guest

    Hi Ade,
    You can't use a string to call the built-in subroutine...try this instead:

    (cond ((eq opt "A")(setq opt +))
    ((eq opt "S")(setq opt -))
    ((eq opt "D")(setq opt /))
    ((eq opt "M")(setq opt *))
    )
     
    Jeff Mishler, Mar 15, 2005
    #2
  3. Adesu

    Adesu Guest

    Hi Jeff,thanks a lot ,it work !

     
    Adesu, Mar 15, 2005
    #3
  4. Give this a try:

    Code:
    ;; 12' 5-1/2" + 6' 3-5/8" = 18' 9-1/8"
    
    (defun C:TEST  (/ key fun input inputA data r)
    (initget "+ - Div")
    (if (setq key (getKword "\nOperation [+/-/Div]: "))
    (progn
    
    (setq fun (eval (read key)))
    
    (cond
    ((= fun +)
    (while	(setq input (getDist "\nInput: "))
    (if input
    (setq data (cons input data))))
    (setq r (apply 'fun data)))
    
    ((= fun -)
    (setq inputA (getDist "\nSubtract base: "))
    (while	(setq input (getDist "\nFollowing number: "))
    (if input
    (setq data (cons input data))))
    (foreach i  data
    (setq inputA (fun inputA i)))
    (setq r inputA))
    
    ((= key "Div")
    (setq inputA (getDist "\nDivide base: "))
    (while	(setq input (getDist "\nFollowing number: "))
    (if input
    (setq data (cons input data))))
    (foreach i  data
    (setq inputA (/ inputA i)))
    (setq r inputA)))
    
    (princ "\nResult: ")
    (princ (rtos r (getvar "lunits") (getvar "luprec")))))
    (princ))
    
    
     
    Luis Esquivel, Mar 15, 2005
    #4
  5. Adesu

    Adesu Guest

    Your code still
    [CHECKING TEXT Test for Add etc.LSP loading...]
    .......
    ; warning: local variable used as function: FUN
    ..
    ; Check done.
    ;---------------------------------------------------------------------------
    ------------
    here my and still problem at
    _$ (prompt "Select Add Subtracts Divides Multiply")
    (initget " A S D M ")
    (setq opt (getkword "\nCHOOSE ONES <A/S/D/M>: "))
    (cond ((eq opt "A")(setq opt +))
    ((eq opt "S")(setq opt -))
    ((eq opt "D")(setq opt /))
    ((eq opt "M")(setq opt *))
    )
    nil
    nil
    "S"
    #<SUBR @01d0f598 ->
    _$ (setq opt -)
    #<SUBR @01d0f598 ->
    ;---------------------------------------------------------------------------
    --------
    this my script completed

    ; cco is stand for create count object
    ; Design by Ade Suharna <>
    ; 15 March 2005
    ; Program no.213/03/2005
    ; Edit by
    (defun c:cco (/ ss ssl cnt ssn opt ttl)
    (prompt "\nCLICK OBJECT TO BE EVALUATION")
    (setq ss (ssget))
    (setq ssl (sslength ss))
    (setq cnt 0)
    (repeat ssl
    (setq ssn (ssname ss cnt))
    (setq sse (entget ssn))
    (setq as1 (atoi (cdr (assoc 1 sse))))
    (set (read (strcat "ss" (itoa cnt))) as1)
    )
    (prompt "Select Add Subtracts Divides Multiply")
    (initget " A S D M ")
    (setq opt (getkword "\nCHOOSE ONES <A/S/D/M>: "))
    (cond ((eq opt "A")(setq opt +))
    ((eq opt "S")(setq opt -))
    ((eq opt "D")(setq opt /))
    ((eq opt "M")(setq opt *))
    )
    (if ss
    (cond
    ((eq ssl 1)(alert "\nInvalid selected,not enough to evaluation"))
    (( eq ssl 2)(setq ttl (opt ss0 ss1)))
    (( eq ssl 3)(setq ttl (opt ss0 ss1 ss2)))
    (( eq ssl 4)(setq ttl (opt ss0 ss1 ss2 ss3)))
    (( eq ssl 5)(setq ttl (opt ss0 ss1 ss2 ss3 ss4)))
    (( eq ssl 6)(setq ttl (opt ss0 ss1 ss2 ss3 ss4 ss5)))
    (( eq ssl 7)(setq ttl (opt ss0 ss1 ss2 ss3 ss4 ss5 ss6)))
    (( eq ssl 8)(setq ttl (opt ss0 ss1 ss2 ss3 ss4 ss5 ss6 ss7)))
    (( eq ssl 9)(setq ttl (opt ss0 ss1 ss2 ss3 ss4 ss5 ss6 ss7 ss8)))
    (( eq ssl 10)(setq ttl (opt ss0 ss1 ss2 ss3 ss4 ss5 ss6 ss7 ss8 ss9)))
    )
    )
    (setq loc (getpoint "\nCLICK LOCATION FOR RESULT OBJECT: "))
    (setq hei 1)
    (command "_text" loc hei "" ttl "")
    (princ ttl)
    )

     
    Adesu, Mar 15, 2005
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.