ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 408|回复: 3

[求助] 求教代码优化

[复制链接]

TA的精华主题

TA的得分主题

发表于 2023-5-23 21:35 来自手机 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
Private Type UnlockType1
    UnlockLine As String * 5
End Type
Private Type UnlockType2
    UnlockLine As String * 4
End Type
Private Type UnlockType3
    UnlockLine As String * 2
End Type
Private Type UnlockType4
    UnlockLine As String * 1
End Type
Private Type UnlockType5
    UnlockLine As String * 38
End Type

Sub JJ07()
    Dim VBAUNLOCK1 As UnlockType1
    Dim VBAUNLOCK2 As UnlockType2
    Dim VBAUNLOCK3 As UnlockType3
    Dim VBAUNLOCK4 As UnlockType4
    Dim IID As UnlockType5
    Dim cID As UnlockType1
    Dim cCMG As UnlockType1
    Dim cDPB As UnlockType1
    Dim cGC As UnlockType2
    Dim c0D0A As UnlockType3
    Dim c20 As UnlockType4
    Dim c00 As UnlockType4
    Dim cFF As UnlockType4
    Open ThisWorkbook.Path & "\USER.DAT" For Binary As #1
        Get #1, 1, cID
        Get #1, 6, cCMG
        Get #1, 11, cDPB
        Get #1, 16, cGC
        Get #1, 20, c0D0A
        Get #1, 22, c20
        Get #1, 23, c00
        Get #1, 24, cFF
    Close #1
End Sub
各位老师,我简单的理解:以上代码是以二进制模式打开USER.DAT文件,并把相应的值赋值给自定义变量;请教有没有办法把USER.DAT这个文件去掉,因为USER.DAT文件是固定,直接把相应的值赋值给cID ,cCMG 。。。,不然运行这段代码还必须有USER.DAT文件配合,图片的用HDX打开USER.DAT
得到的 mmexport1684848885418.jpg

TA的精华主题

TA的得分主题

发表于 2023-5-23 23:06 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
试试:
  1. Private Type UnlockType1
  2.     UnlockLine As String * 5
  3. End Type
  4. Private Type UnlockType2
  5.     UnlockLine As String * 4
  6. End Type
  7. Private Type UnlockType3
  8.     UnlockLine As String * 2
  9. End Type
  10. Private Type UnlockType4
  11.     UnlockLine As String * 1
  12. End Type
  13. Private Type UnlockType5
  14.     UnlockLine As String * 38
  15. End Type

  16. Sub JJ07()
  17.     Dim VBAUNLOCK1 As UnlockType1
  18.     Dim VBAUNLOCK2 As UnlockType2
  19.     Dim VBAUNLOCK3 As UnlockType3
  20.     Dim VBAUNLOCK4 As UnlockType4
  21.     Dim IID As UnlockType5
  22.     Dim cID As UnlockType1
  23.     Dim cCMG As UnlockType1
  24.     Dim cDPB As UnlockType1
  25.     Dim cGC As UnlockType2
  26.     Dim c0D0A As UnlockType3
  27.     Dim c20 As UnlockType4
  28.     Dim c00 As UnlockType4
  29.     Dim cFF As UnlockType4

  30.     cID.UnlockLine = "ID=""{"
  31.     cCMG.UnlockLine = "CMG="""
  32.     cDPB.UnlockLine = "DPB="""
  33.     cGC.UnlockLine = "GC="""
  34.     c0D0A.UnlockLine = Chr(&HD) & Chr(&HA)
  35.     c20.UnlockLine = " "
  36.     c00.UnlockLine = " "
  37.     cFF.UnlockLine = ""
  38. End Sub
复制代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-5-24 08:33 | 显示全部楼层

成功,感谢你的帮助!也帮助我学习了自定义类型
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-16 07:25 , Processed in 0.034080 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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