Testing a setq..?

Discussion in 'AutoCAD' started by C Witt, Jan 7, 2004.

  1. C Witt

    C Witt Guest

    This is probably a basic question.. but i can't find the answer.

    Is there a way of "testing" a setq variable to find out if it is "text"
    or a "number"?

    TIA.
     
    C Witt, Jan 7, 2004
    #1
  2. C Witt

    ECCAD Guest

    Yes,
    (eval var); where var is a variable that has been set
    Example:
    (setq a "a string"); returns "a string"
    (setq b 1.20); returns 1.20 (real)
    !a returns "a string", notice the "" around it, this is a string
    !b returns 1.20, notice no "" around it, this is a real / number
    Bob
     
    ECCAD, Jan 7, 2004
    #2
  3. C Witt

    C Witt Guest

    Thank you. That did exactly what I needed.
     
    C Witt, Jan 7, 2004
    #3
  4. C Witt

    Josh Guest

    numberp
     
    Josh, Jan 7, 2004
    #4
  5. You're welcome.
     
    Jason Piercey, Jan 8, 2004
    #5
  6. C Witt

    C Witt Guest

    (setq test "p")
    (= (type test) STR)
    nil

    Why is this not returning True?
     
    C Witt, Jan 8, 2004
    #6
  7. C Witt

    BillZ Guest

    (= (type test) 'STR)

    T

    Bill
     
    BillZ, Jan 8, 2004
    #7
  8. You need to quote the STR

    (= 'str (type test))
     
    Jason Piercey, Jan 8, 2004
    #8
  9. here is a function to test what type the item is, hth:

    (defun what-type (e / typ)
    (setq typ (type e))
    (cond
    ((eq typ 'ENAME) 'Entity-name)
    ((eq typ 'EXRXSUBR) 'External-ObjectARX-application)
    ((eq typ 'FILE)
    'File-descriptor)
    ((eq typ 'INT)
    'Integer)
    ((eq typ 'LIST)
    'List)
    ((eq typ 'PAGETB)
    'Function-paging-table)
    ((eq typ 'PICKSET)
    'Selection-set)
    ((eq typ 'REAL)
    'Floating-point-number)
    ((eq typ 'SAFEARRAY)
    'Safearray)
    ((eq typ 'STR)
    'String)
    ((eq typ 'SUBR)
    'FAS-or-VLX-file)
    ((eq typ 'SYM)
    'Symbol)
    ((eq typ 'VARIANT)
    'Variant)
    ((eq typ 'USUBR)
    'User-defined-function)
    ((eq typ 'VLA-object)
    'ActiveX-object)))
     
    Luis Esquivel, Jan 8, 2004
    #9
  10. C Witt

    C Witt Guest

    thank you again.
     
    C Witt, Jan 8, 2004
    #10
  11. C Witt

    C Witt Guest

    thank you
     
    C Witt, Jan 8, 2004
    #11
  12. C Witt

    C Witt Guest

    Thank you.

     
    C Witt, Jan 8, 2004
    #12
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.