Author Topic: Data replacement  (Read 5888 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Data replacement
« Reply #15 on: December 05, 2011, 06:22:52 AM »
LEE
COOL!Processing speed is very fast,But the results of processing, integer bit behind" . 00", but the calculation results have no effect.

Thanks myloveflyer  :-)

Sorry, I'm not sure what you mean about the integer bit behind " . 00"?

myloveflyer

  • Newt
  • Posts: 152
Re: Data replacement
« Reply #16 on: December 07, 2011, 11:59:37 PM »
LEE,I mean, if sj.dat there are digital ( for example: 10), your program running results was "10", and in sjold.dat format should be "10.00", but this time I have to deal with a lot of data format requirements is not very strict.
Thanks!
Never give up !

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Data replacement
« Reply #17 on: December 08, 2011, 07:13:14 AM »
LEE,I mean, if sj.dat there are digital ( for example: 10), your program running results was "10", and in sjold.dat format should be "10.00", but this time I have to deal with a lot of data format requirements is not very strict.
Thanks!

I see, try something like this instead:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / *error* i line lst1 lst2 rf1 rf2 rfile1 rfile2 str wf1 wfile1 )
  2.  
  3.     (setq rfile1 "sj.dat"
  4.           rfile2 "sjold.dat"
  5.           wfile1 "sjx.dat"
  6.     )
  7.  
  8.     (defun *error* ( msg )
  9.         (if dimzin (setvar 'DIMZIN dimzin))
  10.         (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
  11.             (princ (strcat "\nError: " msg))
  12.         )
  13.         (princ)
  14.     )
  15.  
  16.     (defun _StringParser ( string delim / pos )
  17.         (if (setq pos (vl-string-search delim string))
  18.             (vl-remove ""
  19.                 (cons
  20.                     (substr string 1 pos)
  21.                     (_StringParser (substr string (+ pos 1 (strlen delim))) delim)
  22.                 )
  23.             )
  24.             (list string)
  25.         )
  26.     )
  27.  
  28.     (defun _ParseFile ( file delim / data line )
  29.         (cond
  30.             (   (setq file (open file "r"))
  31.                 (while (setq line (read-line file))
  32.                     (setq data (cons (_StringParser line delim) data))
  33.                 )
  34.                 (close file)
  35.                 (reverse data)
  36.             )
  37.         )
  38.     )
  39.  
  40.     (defun _PadLeft ( string char len )
  41.         (if (< (strlen string) len)
  42.             (_PadLeft (strcat char string) char len)
  43.             string
  44.         )
  45.     )
  46.  
  47.     (setq dimzin (getvar 'DIMZIN))
  48.     (setvar 'DIMZIN 0)
  49.  
  50.     (cond
  51.         (   (null
  52.                 (and
  53.                     (setq rf1 (findfile rfile1))
  54.                     (setq rf2 (findfile rfile2))
  55.                 )
  56.             )
  57.             (princ (strcat "\n" rfile1 " or " rfile2 " could not be found."))
  58.         )
  59.         (   (null
  60.                 (and
  61.                     (setq lst1
  62.                         (vl-sort
  63.                             (apply 'append
  64.                                 (mapcar
  65.                                     (function
  66.                                         (lambda ( a )
  67.                                             (mapcar
  68.                                                 (function
  69.                                                     (lambda ( b / n )
  70.                                                         (setq b (_StringParser b " "))
  71.                                                         (list (atoi (car b))
  72.                                                             (if (setq n (distof (cadr b)))
  73.                                                                 (rtos n 2 2)
  74.                                                                 (cadr b)
  75.                                                             )
  76.                                                         )
  77.                                                     )                                                
  78.                                                 )
  79.                                                 a
  80.                                             )
  81.                                         )
  82.                                     )
  83.                                     (_ParseFile rf1 ";")
  84.                                 )
  85.                             )
  86.                            '(lambda ( a b ) (< (car a) (car b)))
  87.                         )
  88.                     )
  89.                     (setq lst2 (_ParseFile rf2 "     "))
  90.                 )
  91.             )
  92.             (princ (strcat "\nEither " rfile1 " or " rfile2 " is empty."))
  93.         )
  94.         (   (null (setq wf1 (open (setq wfile1 (strcat (vl-filename-directory rf1) "\\" wfile1)) "w")))
  95.             (princ (strcat "\nUnable to open " wfile1 " for writing."))
  96.         )
  97.         (   t
  98.             (setq i 0)
  99.             (while (setq line (car lst2))
  100.                 (setq str "")
  101.                 (foreach item line
  102.                     (if (and lst1 (= (setq i (1+ i)) (caar lst1)))
  103.                         (setq str  (strcat str (_PadLeft (cadar lst1) " " 9))
  104.                               lst1 (cdr lst1)
  105.                         )
  106.                         (setq str (strcat str (_PadLeft item " " 9)))
  107.                     )
  108.                 )
  109.                 (write-line str wf1)
  110.                 (setq lst2 (cdr lst2))
  111.             )            
  112.             (close wf1)
  113.             (startapp "notepad" wfile1)
  114.         )
  115.     )
  116.     (setvar 'DIMZIN dimzin)
  117.     (princ)
  118. )

myloveflyer

  • Newt
  • Posts: 152
Re: Data replacement
« Reply #18 on: December 08, 2011, 09:26:26 PM »
LEE,Cool!
Thanks, :-D
Good luck
Never give up !

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Data replacement
« Reply #19 on: December 09, 2011, 04:08:19 AM »
You're welcome myloveflyer!  :-)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Data replacement
« Reply #20 on: December 16, 2011, 07:21:12 AM »
Oh from your screenshot, I see what you mean about the space - it only displays up to line 35 for me [using FF8.0 W7], which is similar to the existing code panes so I couldn't see what you were getting at initially.
Odd, I looked at it with FF8.0+Win7. I also upgraded today to 8.0.1 and it still doesn't condense the code. Even 35 lines is a lot.

FWIW, using the 'Core' Swamp theme (the old theme), I see all 101 lines of code displayed - also, the font-size is pretty small.  :|

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Data replacement
« Reply #21 on: December 16, 2011, 08:00:21 AM »
I see, it is a bit small. With 11 people using it Mark may not have noticed it was small.
I'll bring it to his attention.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Data replacement
« Reply #22 on: December 16, 2011, 08:15:37 AM »
FWIW, using the 'Core' Swamp theme (the old theme), I see all 101 lines of code displayed - also, the font-size is pretty small.  :|
Don't use the Core Theme. That's an easy one. :)

It's nothing major, just some adjustment in the settings will fix it. If it's not fixed by Monday give me a shout.
TheSwamp.org  (serving the CAD community since 2003)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Data replacement
« Reply #23 on: December 16, 2011, 09:12:44 AM »
FWIW, using the 'Core' Swamp theme (the old theme), I see all 101 lines of code displayed - also, the font-size is pretty small.  :|
Don't use the Core Theme. That's an easy one. :)

Oh, don't worry, I don't personally use it - I was just curious as to why the code frame was being displayed differently  :-)