Author Topic: Checking for user input  (Read 1737 times)

0 Members and 1 Guest are viewing this topic.

Cuddles

  • Guest
Checking for user input
« on: December 17, 2014, 08:31:23 PM »
Hello all,

Having a brain fade moment and need some help refreshing my memory with conditional statements.

I wish to check that a user has entered a number (real or integer) and not a character (a, b, c etc...). Obviously this will use an "if", "cond", "while" etc... functions.
Could someone quickly please advise me on how to do this.

What this is being used for is not important.

Cheers,

Cuddles

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Checking for user input
« Reply #1 on: December 17, 2014, 08:38:48 PM »
Look at the getreal function.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Cuddles

  • Guest
Re: Checking for user input
« Reply #2 on: December 17, 2014, 10:47:59 PM »
Hi Ronjonp,

I wish to allow the user to obtain values from both direct keyboard input and from the screen.
I suppose I could use getdist.

Thanks,

Cuddles

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Checking for user input
« Reply #3 on: December 18, 2014, 12:59:28 AM »
Getdist is another option :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Checking for user input
« Reply #4 on: December 18, 2014, 03:22:03 AM »
Look at the function Initget,   snippet:
Code: [Select]
1 (bit 0) Prevents the user from responding to the request by entering only ENTER.
2 (bit 1) Prevents the user from responding to the request by entering zero.
4 (bit 2) Prevents the user from responding to the request by entering a negative value.
8 (bit 3) Allows the user to enter a point outside the current drawing limits.
...
and with getdist use a funtion like this (very old):
Code: [Select]
; ---------- Source files from: --------------------------------------------
; These functions are freeware courtesy of the author's of "Inside AutoLisp"
; for rel. 10 published by New Riders Publications. This credit must
; accompany all copies of this function.
; Modified by Alessi Marc'Antonio
;
; IGtBit > (0 for none) and KwdStr key word ("" for none) same of INITGET
; PrmStr = prompt string, a default real will be added
;          as <DefRea> (nil for none) and a : will be added
; BasPtn = base point (nil for none)
;
; Example:
; (setq #GlVal (uDist 46 "" "Width" #GlVal (getvar "LASTPOINT")))
;
(defun uDist (IGtBit KwdStr PrmStr DefRea BasPtn / InpVal)
  (if DefRea
    (setq
      PrmStr (strcat "\n" PrmStr " <" (ALE_RTOS_DZ8 DefRea) ">: ")
      IGtBit (logand IGtBit 254)
    )
    (setq PrmStr (strcat "\n" PrmStr ": "))
  )
  (initget IGtBit KwdStr)
  (setq InpVal (if BasPtn (getdist BasPtn PrmStr) (getdist PrmStr)))
  (if InpVal InpVal DefRea)
)
(defun ALE_RtoS_DZ8 (ReaVal / CurDZn OutVal)
  (if (= 8 (setq CurDZn (getvar "DIMZIN")))
    (setq CurDZn nil)
    (setvar "DIMZIN"
  )
  (setq OutVal (rtos ReaVal 2))
  (and CurDZn (setvar "DIMZIN" CurDZn))
  OutVal
)

Cuddles

  • Guest
Re: Checking for user input
« Reply #5 on: December 18, 2014, 07:06:47 PM »
Hi folks,

I've finally solved my problem  :-), but any comments are still welcome.

Cheers,

Cuddles