Accept of uppercase and lowercase

Discussion in 'AutoCAD' started by Adesu, Jul 29, 2004.

  1. Adesu

    Adesu Guest

    Hi Alls,I want input from user able received "uppercase or lowercase",how to
    put them in "if",can you suggest me,thanks.
    Best regards
    Ade Suharna

    (setq name "M10")
    (setq typ (getstring "\nSelect Bolt Type : ")
    (if (/= typ name)(alert (strcat "\nYOUR CHOOSE IS WRONG
    \nPlease try again,choose one
    \nM4 M5 M6 M8 M10 M12 M14 M16 M20 M24")))
    (if (= typ ???)(progn bla bla.....bla

    ??? = uppercase/lowercase
     
    Adesu, Jul 29, 2004
    #1
  2. Adesu

    Paul Turvill Guest

    Good programming practice avoids problems with the case of user input by
    either using properly formatted keywords, or by processing the input with
    the (strcase ... ) function. If your program needs an ALL CAPS input,
    (strcase txt) will convert the variable txt to ALL CAPS; if it needs lower
    case, then (strcase txt T) will convert it to lowercase:

    Command: (strcase "Hello")
    "HELLO"
    Command: (strcase "HELLO" T)
    "hello"
    Command: (strcase "m10")
    "M10"
    ___
     
    Paul Turvill, Jul 29, 2004
    #2
  3. Adesu

    Adesu Guest

    Hi Paul,this is my program after follow your suggest,thanks a lot

    (setq name "M10")
    (setq typ (strcase (getstring "\nSELECT TYPE OF BOLT : " T)))
    (if (= typ name)(alert (strcat "\nYOUR CHOOSE IS RIGHT
    \nPlease go on"))
    (alert (strcat "\nYOUR CHOOSE IS WRONG
    \nPlease try again,choose one
    \nM4 M5 M6 M8 M10 M12 M14 M16 M20 M24")))
     
    Adesu, Jul 29, 2004
    #3
  4. Adesu

    Jürg Menzi Guest

    Hi Ade

    You can use 'getkword' together with a 'initget' filter:

    Code:
    ;Set initget string with bolt sizes:
    (initget "M4 M5 M6 M8 M10 M12 M14 M16 M20 M24")
    
    ;Set default value to M10 if variable BltTyp is nil:
    (setq BltTyp (cond (BltTyp) ("M10"))
    
    ;Set first part of prompt string (otherwise the next line would be too long)
    TmpPmt "\nSelect Bolt Type [M4/M5/M6/M8/M10/M12/M14/M16/M20/M24]"
    
    ;User input for bolt size or default value by pressing 'Enter'.
    ;The method with 'initget' and '[M4/M5/M6...' allows the user to select the
    ;appropriate value by left mouse click from context menu:
    BltTmp (getkword (strcat TmpPmt " <" BltTyp ">: "))
    
    ;Set BltTyp to user input else (if user had pressed 'Enter') to default value
    BltTyp (cond (BltTmp) (BltTyp))
    );end setq
    
    ;Do your stuff with 'BltTyp'
    (cond
    ((eq BltTyp "M4")... do M4 stuff)
    ((eq BltTyp "M5")... do M5 stuff)
    ...
    
    Cheers
     
    Jürg Menzi, Jul 29, 2004
    #4
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.