Author Topic: Using "ADODB.Stream" Read/Write stream  (Read 4985 times)

0 Members and 1 Guest are viewing this topic.

cjw

  • Guest
Using "ADODB.Stream" Read/Write stream
« on: October 30, 2009, 12:19:50 AM »
Read / Write Stream
http://www.theswamp.org/index.php?topic=17465.msg210365
The "Scripting.FileSystemObject" can't  write stream.
(vlax-invoke stream 'Write text) ->return nil.

So i try to use "ADODB.Stream"
But also have something wrong with "write"

May be this link could give you some ideas.
http://www.motobit.com/tips/detpg_read-write-binary-files/
Code: [Select]
(defun CJW-STREAMREAD (FILENAME / ADODB TEXT)
  (vl-catch-all-apply
    '(lambda ()
       (setq ADODB (vlax-get-or-create-object "ADODB.Stream"))
       (if (= (vlax-get-property ADODB 'STATE) 1)
(vlax-invoke ADODB 'close)
       )
       ;;adTypeBinary =1  读写流的格式为二进制
       (vlax-put-property ADODB 'type 1)
       ;;打开流
       (vlax-invoke ADODB 'open)
       ;;加载文件
       (vlax-invoke ADODB 'LOADFROMFILE FILENAME)
       ;;重置指针
       (vlax-put-property ADODB 'POSITION 0)
       ;;读取流
       (setq VAR (vlax-invoke-method
  ADODB
  'read
  (vlax-get ADODB 'SIZE)
)
       )
       ;;重置指针
       (vlax-put-property ADODB 'POSITION 0)
       ;;以二进制格式写入文件流
       (vlax-invoke-method ADODB 'WRITE VAR)
       ;;重置指针
       (vlax-put-property ADODB 'POSITION 0)
       ;;adTypeText =2   读写流的格式为字符串
       (vlax-put-property ADODB 'type 2)
       ;;代码类型
       (vlax-put-property ADODB 'CHARSET "us-ascii")
       ;;以字符串格式读取流
       (setq TEXT (vlax-invoke ADODB 'READTEXT))
       ;;关闭流
       (vlax-invoke ADODB 'close)
     )
  )
  (and ADODB (vlax-release-object ADODB))
  TEXT
)

(defun CJW-STREAMWRITE (PATH TEXT / ADODB)
  (vl-catch-all-apply
    '(lambda ()
       (setq ADODB (vlax-create-object "ADODB.Stream"))
       (if (= (vlax-get-property ADODB 'STATE) 1)
(vlax-invoke ADODB 'close)
       )
       ;;打开流
       (vlax-invoke ADODB 'open)
       ;;adTypeText =2   读写流的格式为字符串
       (vlax-put-property ADODB 'type 2)
       ;;代码类型
       (vlax-put-property ADODB 'CHARSET "us-ascii")
       ;;重置指针
       (vlax-put-property ADODB 'POSITION 0)
       ;;以字符串格式写入流
       (vlax-invoke ADODB 'WRITETEXT TEXT)
       ;;保存文件
       (vlax-invoke ADODB 'SAVETOFILE PATH 2)
       ;;关闭流
       (vlax-invoke ADODB 'close)
     )
  )
  (and ADODB (vlax-release-object ADODB))
)

(defun C:TT ()
  (setq TEXT (CJW-STREAMREAD "C:\\ARC.SLD"))
  (CJW-STREAMWRITE "c:\\NEW.SLD" TEXT)
  (princ)
)

Can't return the right file.
Wishing for a good solution!!!
Thanks!!!
« Last Edit: November 01, 2009, 10:26:26 PM by cjw »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Using "ADODB.Stream" Read/Write stream
« Reply #1 on: October 30, 2009, 12:34:32 AM »
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.

cjw

  • Guest
Re: Using "ADODB.Stream" Read/Write stream
« Reply #2 on: October 30, 2009, 04:44:47 AM »
Have you read this thread?
http://www.theswamp.org/index.php?topic=10101.0

No,CAB
Thank you~
Nice code.
I have to pay 2 days to understand it.

cjw

  • Guest
Re: Using "ADODB.Stream" Read/Write stream
« Reply #3 on: November 01, 2009, 10:25:20 PM »
After After thinking long time.
Have no good result.
The result is in sight,but i can't catch it. so hard. :-(
Please give me favor!!!