乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 19|回复: 0

在VBA中实现LISP中findfile()函数功能

[复制链接]

1

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2011-4-22 22:01:00 | 显示全部楼层 |阅读模式
函数内容:
Function FindFile(strFile As String)
Dim PrefFile As AcadPreferencesFiles
Dim curSupportPath As String
Dim numPath As Integer
Dim strPath As String
Dim pathName As String
Dim PathTF As Boolean
Dim SearchPath As String
Dim appPath As string
Set PrefFile = ThisDrawing.Application.Preferences.Files
curSupportPath = PrefFile.SupportPath
PathTF = True
pathName = CurDir() & "\" & strFile
If Dir(pathName) = "" Then
    appPath = ThisDrawing.Application.Path
    PathName = appPath & "\" & strFile
    If Dir(pathName) = "" Then
        Do While PathTF
        numPath = InStr(1, curSupportPath, ";", 1)
        If numPath = 0 Then
            strPath = curSupportPath
            PathTF = False
        Else
            strPath = Left(curSupportPath, numPath - 1)
            curSupportPath = Right(curSupportPath, Len(curSupportPath) - numPath)
        End If
        pathName = strPath & "\" & strFile
        If Dir(pathName)  "" Then
            SearchPath = pathName
            Exit Do
        End If
        Loop
        pathName = strPath & "\" & strFile
        If Dir(pathName) = "" Then
            SearchPath = ""
        End If
    Else
        SearchPath = pathName
    End If
Else
    SearchPath = pathName
End If
FindFile = SearchPath
End Function
  参数:
一个文件名
  注意:
在LISP中, findfile()函数的功能是在的当前目录、autoCAD目录及autoCAD的支持目录下查找所需的文件,如果找到文件,则返回文件的路径及文件名称,如不能找到文件,则返回空字符。
在VBA中,没有相应的函数来完成该功能,而必须使用绝对路径来引用文件,这就为VBA在autoCAD中的使用带来麻烦,有时你编制了一个VBA程序,并提供给用户,由于用户安装的路径和你程序调试的路径不同,致使程序运行出错。
这种情况会经常发生的,因为你无权要求用户必须将程序放在哪个固定的目录下。
  示例:
strPathFile = FindFile("tyl.ini")
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-6-30 23:13 , Processed in 0.953715 second(s), 55 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表