找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 574|回复: 1

[VBA程序]:Compress Lisp Files

[复制链接]

已领礼包: 181个

财富等级: 日进斗金

发表于 2002-10-18 10:34:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
Compress Lisp Files

  1. [FONT=courier new]  
  2. Option Explicit
  3. Dim lngDataCount As Long
  4. Dim lngBufferStart As Long
  5. Dim lngMxBuffSize As Long
  6. Dim strBuffer As String
  7. Dim lngBuffOffset As Long
  8. Dim lngBuffSize As Long
  9. Dim strDatContrl As String
  10. Dim bytDataCntrlChar As Byte
  11. Dim lngCntr As Long
  12. Dim bytCntrlPos As Byte
  13. Dim lngCompLen As Long
  14. Dim lngCompPos As Long
  15. Dim lngBytCompLen As Long
  16. Dim lngControlPos As Long
  17. Dim bytCntrlBitPos As Byte
  18. Dim lngDataPos As Long
  19. Dim lngDecompStart As Long
  20. Dim lngDecompLen As Long

  21. Public Function LispCompress(strCompName As String) As String
  22.     lngMxBuffSize = 55535
  23.     lngBytCompLen = 255
  24.     lngBufferStart = 0
  25.     strDatContrl = ""
  26.     bytDataCntrlChar = 0
  27.     bytCntrlPos = 0
  28.     lngCntr = 0
  29.     If Len(strCompName) > 4 Then
  30.         LispCompress = Left(strCompName, 4)
  31.         For lngDataCount = 5 To Len(strCompName)
  32.             If lngDataCount > lngMxBuffSize Then
  33.                 lngBuffSize = lngMxBuffSize
  34.                 lngBufferStart = lngDataCount - lngMxBuffSize
  35.             Else
  36.                 lngBuffSize = lngDataCount - 1
  37.                 lngBufferStart = 1
  38.             End If

  39.             strBuffer = Mid(strCompName, lngBufferStart, lngBuffSize)
  40.             If Len(strCompName) - lngDataCount < lngBytCompLen Then lngBytCompLen = Len(strCompName) - lngDataCount
  41.             lngCompPos = 0
  42.             For lngCompLen = 3 To lngBytCompLen Step 3
  43.                 If lngCompLen > lngBytCompLen Then
  44.                     lngCompLen = lngBytCompLen
  45.                 End If
  46.                 lngCompPos = InStr(1, strBuffer, Mid(strCompName, lngDataCount, lngCompLen), 0)
  47.                 If lngCompPos = 0 Then
  48.                     If lngCompLen > 3 Then
  49.                         While lngCompPos = 0
  50.                             lngCompPos = InStr(1, strBuffer, Mid(strCompName, lngDataCount, lngCompLen - 1), 0)
  51.                             If lngCompPos = 0 Then lngCompLen = lngCompLen - 1
  52.                         Wend
  53.                     End If
  54.                     lngCompLen = lngCompLen - 1
  55.                     Exit For
  56.                 End If
  57.             Next
  58.             If lngCompLen > lngBytCompLen And lngCompPos > 0 Then
  59.                 lngCompLen = lngBytCompLen
  60.                 lngCompPos = InStr(1, strBuffer, Mid(strCompName, lngDataCount, lngCompLen), 0)
  61.             End If
  62.             If lngCompPos > 0 Then
  63.                 lngBuffOffset = lngBuffSize - lngCompPos + 1
  64.                 LispCompress = LispCompress & Chr((lngBuffOffset And &HFF00) / &H100) & Chr(lngBuffOffset And &HFF) & Chr(lngCompLen)
  65.                 lngDataCount = lngDataCount + lngCompLen - 1
  66.                 bytDataCntrlChar = bytDataCntrlChar + 2 ^ bytCntrlPos
  67.             Else
  68.                 LispCompress = LispCompress & Mid(strCompName, lngDataCount, 1)
  69.             End If
  70.             bytCntrlPos = bytCntrlPos + 1
  71.             If bytCntrlPos = 8 Then
  72.                 strDatContrl = strDatContrl & Chr(bytDataCntrlChar)
  73.                 bytDataCntrlChar = 0
  74.                 bytCntrlPos = 0
  75.             End If

  76.             lngCntr = lngCntr + 1
  77.             If lngCntr / 1000 = Int(lngCntr / 1000) Then
  78.             DoEvents
  79.             End If
  80.         Next
  81.         If bytCntrlPos <> 0 Then strDatContrl = strDatContrl & Chr(bytDataCntrlChar)
  82.         LispCompress = Chr((lngCntr And &H8F000000) / &H1000000) & Chr((lngCntr And &HFF0000) / &H10000) & Chr((lngCntr And &HFF00) / &H100) & Chr(lngCntr And &HFF) & Chr((Len(strDatContrl) And &H8F000000) / &H1000000) & Chr((Len(strDatContrl) And &HFF0000) / &H10000) & Chr((Len(strDatContrl) And &HFF00) / &H100) & Chr(Len(strDatContrl) And &HFF) & strDatContrl & LispCompress
  83.     Else
  84.         LispCompress = strCompName
  85.     End If

  86. End Function

  87. [/FONT]



  1. [FONT=courier new]
  2. Public Function LispUncompress(strUnComName As String) As String
  3. If Len(strUnComName) > 4 Then
  4.         lngCntr = Asc(Left(strUnComName, 1)) * &H1000000 + Asc(Mid(strUnComName, 2, 1)) * &H10000 + Asc(Mid(strUnComName, 3, 1)) * &H100 + Asc(Mid(strUnComName, 4, 1))
  5.         lngDataCount = Asc(Mid(strUnComName, 5, 1)) * &H1000000 + Asc(Mid(strUnComName, 6, 1)) * &H10000 + Asc(Mid(strUnComName, 7, 1)) * &H100 + Asc(Mid(strUnComName, 8, 1)) + 9
  6.         LispUncompress = Mid(strUnComName, lngDataCount, 4)
  7.         lngDataCount = lngDataCount + 4
  8.         bytCntrlBitPos = 0
  9.         lngControlPos = 9
  10.         For lngDataPos = 1 To lngCntr
  11.             If 2 ^ bytCntrlBitPos = (Asc(Mid(strUnComName, lngControlPos, 1)) And 2 ^ bytCntrlBitPos) Then
  12.                 lngDecompStart = Len(LispUncompress) - (CLng(Asc(Mid(strUnComName, lngDataCount, 1))) * &H100 + CLng(Asc(Mid(strUnComName, lngDataCount + 1, 1)))) + 1
  13.                 lngDecompLen = Asc(Mid(strUnComName, lngDataCount + 2, 1))
  14.                 LispUncompress = LispUncompress & Mid(LispUncompress, lngDecompStart, lngDecompLen)
  15.                 lngDataCount = lngDataCount + 3
  16.             Else
  17.                 LispUncompress = LispUncompress & Mid(strUnComName, lngDataCount, 1)
  18.                 lngDataCount = lngDataCount + 1
  19.             End If
  20.             bytCntrlBitPos = bytCntrlBitPos + 1
  21.             If bytCntrlBitPos = 8 Then
  22.                 bytCntrlBitPos = 0
  23.                 lngControlPos = lngControlPos + 1
  24.             End If
  25.         Next
  26.     Else
  27.         LispUncompress = strUnComName
  28.     End If
  29. End Function[/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-10-29 21:29:50 | 显示全部楼层
谢谢!加10分。

能给大家介绍下程序的作用吗?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2025-9-6 16:24 , Processed in 0.178049 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表