Bryco 发表于 2007-6-10 12:20:30

删除不需要的支持路径

我编写了一些代码来删除不再需要的支持路径
我正在使用replace函数,但我知道我一定是做错了什么,因为它;“应该”;保留我当前的路径,只删除要删除的指定路径。出于某种原因,它也被从我当前的一些路径中删除
我知道它一定是我的Replace函数中的某个东西,但我不确定是什么
如果有人能帮我解决这个问题,我将不胜感激
谢谢MarkSub DeleteFileSearchPaths()
Dim CurrPaths, DeletePath(5), NewPaths As String
Dim Preferences As AcadPreferences
Dim dpcount As Integer
Set Preferences = ThisDrawing.Application.Preferences
CurrPaths = Preferences.Files.SupportPath
'Paths you want to delete
DeletePath(0) = "I:\PATH\PATH"
DeletePath(1) = "K:\PATH\PATH"
DeletePath(2) = ""
DeletePath(3) = ""
DeletePath(4) = ""
               
               
               
For dpcount = 0 To 4
NewPaths = Replace(NewPaths, CurrPaths, DeletePath(5), 1, vbTextCompare)
Next dpcount
Preferences.Files.SupportPath = NewPaths
End Sub


Bryco 发表于 2007-6-10 13:30:31

NewPaths=Replace(NewPaths,CurrPaths,DeletePath(5),1,vbTextCompare)
1)在这里,您使用NewPaths作为搜索字符串,但它是空的,因此您将删除路径
电流路径现在是你的搜索字符串,错了
DeletePath(5)不是一个字符串,如果正确地将其暗显,则它是一个字符串数组
试试这个(你仍然需要得到正确的答案);DeletePath(5)作为字符串
NewPaths=Replace(CurrPaths,deleteppath(dpcount),&quot",1,vbTextCompare)

Bryco 发表于 2007-6-11 09:30:09


嘿,布莱,是的,我认为你是对的,我不知道;我不认为我的替换功能做得很对,这就是为什么我有这样的问题
是的,它本质上应该是当前路径-删除路径,我认为这是你建议的
另外,你是对的,我确实需要处理分号
我想这就是我需要的:NewPaths = Replace(CurrPaths &";" , DeletePath(dpcount), "", 1, vbTextCompare)
我们会看到的谢谢你Mark

Bryco 发表于 2007-6-11 13:01:58


布莱,你的建议不起作用:NewPaths = Replace(CurrPaths, DeletePath(dpcount), "", 1, vbTextCompare)
还有其他建议吗?我将不胜感激
同样,在这种情况下,我不't认为分号(是必要的。
标记

Bryco 发表于 2007-6-11 13:29:48


Duh,为什么不'我一开始没想过吗
现在它工作得很好,答案是:
Sub DeleteFileSearchPaths()
Dim CurrPaths, DeletePath(5)
Dim Preferences As AcadPreferences
Dim dpcount As Integer
Set Preferences = ThisDrawing.Application.Preferences
CurrPaths = Preferences.Files.SupportPath
'Paths you want to delete
DeletePath(0) = "I:\Path\Path"
DeletePath(1) = "K:\Path\Path"
DeletePath(2) = ""
DeletePath(3) = ""
DeletePath(4) = ""
               
               
               
For dpcount = 0 To 4
CurrPaths = Replace(CurrPaths, DeletePath(dpcount), "", 1, vbTextCompare)
Next dpcount
Preferences.Files.SupportPath = CurrPaths
End Sub
我们错过了显而易见的事情;Currpaths是用于保存当前支持路径的变量集
CurrPaths = Preferences.Files.SupportPath
在这种情况下,当使用replace函数时,我们只想将currpaths(保存当前路径)替换为currpatys=currpathers-deletepaths,最终结果为:Preferences.Files.SupportPath = CurrPaths(currpaths = currpaths - deletepaths)
我希望这有意义
无论如何,它正在按计划工作

Bryco 发表于 2007-6-11 20:58:31

做得好。

Bryco 发表于 2007-6-11 22:41:10


好的,谢谢你;
页: [1]
查看完整版本: 删除不需要的支持路径