Jump to content

Need Help to keep my data with an argument


Michaels

Recommended Posts

Hello.

 

I wonder why these codes are not working good and return an error message .

 

   (setq a (if a b "1"))
 (if (progn (initget (+ 1 2 4) "1/4 1/2 2 1.5")
  (setq a (cond ((getkword (strcat "\n Enter Inch Number [1/4 1/2 2 1.5] <"(atoi a 3 2)" > :")))(T a))))
     (setq b a)
  )

Thanks

Link to comment
Share on other sites

At least use "\" to give the illusion of fraction

 

 
(setq a (if a b "1"))
(if (progn
(initget (+ 1 2 4) [color=blue]"1\\4 1\\2 2 1.5")[/color]
(setq a (cond
((getkword (strcat "\n Enter Inch Number [[color=blue]1\\4/1\\2/2/1.5][/color] <"
[color=blue]a[/color]" > :")))(T a))))
(setq b a)
)

 

To get a better appearance make sure dynmode is set to 1

 

no need for a variable conversion

 

BTW:

http://lee-mac.com/promptwithdefault.html for default tutorial

Link to comment
Share on other sites

Thanks .

 

But that does not save the given data to variable a which is need to be changed according to the last given data .

 

I guess that failed due to the un-existence of (atoi a 3 2) .

 

What you think .

Link to comment
Share on other sites

ah.... i see

 

by doing the "\" you cant convert varaible a to a floating number

but if you use "/" , it cant be recognize by getkword as 1/4

Maybe therse a escape code for that... hmmmm

 

BTW use distof instead, 1/4 is 0.25 , converting 1/4 to integer will result to 1, besides there is no mode argument for itoa

 

I'll get back to you... hang on

Link to comment
Share on other sites

Think about what type of data the variable 'a' points to:

 

(setq a (cond ( a ) ("1")))

(if
 (progn (initget "0.25 0.5 2 1.5")
   (setq a
     (cond
       (
         (getkword
           (strcat "\n Enter Inch Number [0.25/0.5/2/1.5] <" a "> :")
         )
       )
       ( a )
     )
   )
 )
 (princ (strcat "You have Selected: " a))
)

Link to comment
Share on other sites

Thank you Lee.

 

Although that would save the chosen number by a user to the argument , the second time that I use it I can not

hit enter to get the last saved number to the variable .:?

Link to comment
Share on other sites

Although that would save the chosen number by a user to the argument , the second time that I use it I can not

hit enter to get the last saved number to the variable .:?

 

It saves it to a variable, not argument. You had the initget bit 1 set preventing the user from pressing enter - I edited my post to removed the initget bit values.

 

Since you require a 'real' value, I would be more inclined to approach it this way:

 

(defun c:test ( / allowedvalues tmp )

 (setq allowedvalues '(0.25 0.5 2.0 1.5) *def* (cond ( *def* ) ( (car allowedvalues) )))

 (while
   (not
     (member
       (setq tmp
         (cond
           (
             (getreal
               (strcat "\nEnter Inch Number [0.25/0.5/2.0/1.5] <" (rtos *def* 2 2) ">: ")
             )
           )
           ( *def* )
         )
       )
       allowedvalues
     )
   )
   (princ "\nPlease Select from [0.25/0.5/2.0/1.5].")
 )
 (setq *def* tmp)

 (princ (strcat "\nYou have selected: " (rtos *def* 2 2)))
 (princ)
)

Link to comment
Share on other sites

oh welll. i'm too slow of a typist .. i was about to suggest using decimal instead of fraction.

but i could have sworn i've done it once... i'll keep digging

 

EDIT: geez Lee, you sure can code and type fast....:)

Link to comment
Share on other sites

EDIT: geez Lee, you sure can code and type fast....:)

 

Too much practice :oops:

 

That's more than great Lee . Thank you :)

 

A great Thanks also to pBe .

 

Appreciated a lot.

 

You're welcome Michaels - hopefully my code is understandable.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...