大家好,
昨天我在试验读取条形码值。
但在这个例子中,我会尽量保持简单:
- ; Example input: 0011 0012 0033... 00XX
- ; split 0011 to 00 and 11 (the first and 2nd character are separated from 3rd and 4th)
- ; store 00 value and calculate 11 value (first and 2nd character is stored, and 3rd with 4rth are used for calculations)
- ; list is constructed with the calculation values
- ; sum the total of the calculation values in the while loop
- ; when loop is exited display the grand total of calculation values
- (defun C:test (/ lst calc-val-list )
- (setq lst '( 0 ))
- (while
- (setq get-val (getstring t "\nInput value: ")) ; example 0011
- (setq code-val (strcat (substr get-val 1 2 ))) ; stored 00
- (setq calc-val (strcat (substr get-val 3 2 ))) ; stored 11 string
- (setq calc-val-num (strcat (rtos (atof calc-val) 2 5) )) ; stored 11 number
- (princ (strcat "\nCode-val: " code-val " " )) ; display 00 for check
- (princ (strcat "\nCalc-val: " calc-val-num " " )) ; display 11 number for check
- (setq calc-val-list (append '(calc-val-num) lst)) ; constructs a list with the stored values (calc-val-num) ; <---- problem here?
- (princ (strcat "\nCalc-val-list: " calc-val-list " " )) ; this doesn't print, problem?, cannot check
- );while
- (setq grand-total (apply '+ (calc-val-list)) ) ; sums the items in the list ; <---- problem here?
- (princ (strcat "\nGrand-total: " grand-total " " )) ; this doesn't print, problem?, cannot check
- (princ)
- );defun
为此:
- (setq calc-val-list (append '(calc-val-num) lst)) ; constructs a list with the stored values (calc-val-num) ; <---- problem here?
- (princ (strcat "\nCalc-val-list: " calc-val-list " " )) ; this doesn't print, problem?, cannot check
|