Jump to content

calculator using dcl & lisp


Ramana

Recommended Posts

Hello Friends,

 

Greetings,

 

I am trying with DCL programing for Basic calculator. i have defined buttons for all numbers and functions. i am able to display a number in the edit box, how to control the display of all picked buttons till i pressed any function button.

 

please give me an basic idea to proceed with lisp program

 

Thanks in advance

 

Ramana

Link to comment
Share on other sites

Are you doing this just to do it?

 

I only ask as AutoCAD includes a pretty good calculator already... Use Ctrl + 8 to toggle view.

Link to comment
Share on other sites

Are you doing this just to do it?

 

I only ask as AutoCAD includes a pretty good calculator already... Use Ctrl + 8 to toggle view.

 

Or you can find it near the bottom of your right click shortcuts menu. If you expand it to see the whole thing you can set and save your own constant or function based variables and customizations there, as well as all manner of rapid preset conversions. :)

quick calculator.jpg

Edited by Dadgad
Link to comment
Share on other sites

To address your DCL question, I’m afraid that is not possible to identify if the user inputted an operator (+, -, * or /) while filing the edit_box. This is because DCL doesn’t have a key event; the only event is ACTION_TILE which occur when the user move to other tile. So you will need to rely only on buttons to input the operators.

 

Regards,

Mircea

Link to comment
Share on other sites

Thinking twice on this I will say that there is a solution – the ACTION_TILE event is triggered also when user press while inputting in the edit_box; so if the user is instructed to press after an operand key you can read the content of the tile, retain the last character (validate it if is an accepted operand, remove it if not) as function in use and clean the tile to next input. But, things will get complicated if the user forget to press after an operand.

 

Regards,

Mircea

Link to comment
Share on other sites

The only way I know of how to successfully monitor keystrokes within LISP is to code yourself a .NET LispFunction Method which uses the System.Windows.Forms Namespace for KeyPress, or KeyDown Event to return the Keys Enumeration. :thumbsup:

Link to comment
Share on other sites

  • 2 weeks later...

You can however use slide_image as buttons, a year ago i tried to create a DCL caculator just for the fun of it. i dropped the idea as I cant get around all those arithmetic functions especilly "divide" :lol:

 

Attached is my failed attempt, maybe you'll have better luck with it.

 

calc.jpg

 

(defun c:calD ( / _operand _values curV STotal nums) 
(vl-load-com)      
(defun _operand (lst sym  / a)
     (set_tile "Total"
     (setq a (if (>= (length lst) 2)
          (rtos (eval (cons (eval (read sym)) (mapcar 'atof lst))) 2)
         (car lst))))
      a
     )
(defun _values  (var str)
     (setq var (strcat var
                       (if (and (wcmatch var "*.*")
                 (eq str "."))  "" str)))
     )      
(setq curV "" STotal "" nums nil)
(setq Dcl_sm (load_dialog "CALCD.DCL"))
  (new_dialog "Numbers" Dcl_sm)
      (set_tile "Title" " pBe Calculator")
(start_image "Title")
(foreach slnm (setq vls '("1" "2" "3" "4" "5" "6" "7"
                    "8" "9" "0" "iplus" "iminus" "idivide"
                    "iequal" "imultiply" "idot" "iCan"))
 (setq _X (dimx_tile slnm))
 (setq _Y (- (dimy_tile slnm) 2))(end_image)
 (start_image slnm)(slide_image 1 1 _X _Y slnm)

)(end_image)
(foreach dgt '("1" "2" "3" "4" "5" "6" "7" "8" "9" "0" )
      (action_tile dgt
(vl-prin1-to-string
           (quote (progn
                        (setq curV (_values curv $key))
                        (set_tile "Total" curV)))))
)     
(action_tile "idot"
     "(setq curV (_values curV \".\"))
  (set_tile \"Total\" curV)  ")
(action_tile "iminus"
     "(setq nums (cons curV nums))
      (setq STotal (_operand  nums  (setq sy \"-\")) curV \"\") ")  
(action_tile "imultiply"
     "(setq nums (cons curV nums))
      (setq STotal (_operand  nums (setq sy \"*\")) curV \"\") ")     
(action_tile "iplus"
     "(setq nums (cons curV nums))
      (setq STotal (_operand  nums  (setq sy \"+\")) curV \"\") ")      
(action_tile "iequal"
     "(set_tile \"T\" (setq STotal (_operand  (cons curV nums) sy)))(setq curV \"\" nums nil)")
(action_tile "iCan" "(setq curV \"\" nums nil)(set_tile \"Total\" \"\") ")      
(action_tile "accept" "(done_dialog 1)")
(start_dialog)
(unload_dialog Dcl_sm)
STotal
)

 

You're going to have to crate your own slides for some reasons it wont accept it here as attachment

 

HTH

CALCD.DCL

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...