TheSwamp
Code Red => VB(A) => Topic started by: ML on June 10, 2007, 12:20:30 PM
-
I wrote some code to delete support paths that I no longer need.
I am using the replace function but I know I must have done something wrong as it "should" be retaining my current paths and just deleting the designated paths to delete. For some reason it is taken out some of my current paths as well.
I know it must be something in my Replace Function but I am not sure what.
If someone can help me figure it out, I would appreciate it.
Thanks
Mark
Sub 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
-
NewPaths = Replace(NewPaths, CurrPaths, DeletePath(5), 1, vbTextCompare)
1)Here you are using NewPaths as a searchstring but it is empty so you will delete paths.
2)CurrPaths is now your findstring, wrong.
3) DeletePath(5) is not a string, if you dim it correctly it is an array of strings.
Try this (you still need to get the ";" correct)
Dim DeletePath(5) as string
NewPaths = Replace(CurrPaths, DeletePath(dpcount), "", 1, vbTextCompare)
-
Hey Bry
Yes, I think you are right, I don't think I did the replace function quite right and that is why I am having the problem that I am.
Yes, it should essentially be current paths - delete paths, which I think you are suggesting.
Also, you are correct, I do need to address the semi colon.
I think this is what I will need:
NewPaths = Replace(CurrPaths & ";" , DeletePath(dpcount), "", 1, vbTextCompare)
We will see
Thank you
Mark
-
Bry,
Your suggestion did not work:
NewPaths = Replace(CurrPaths, DeletePath(dpcount), "", 1, vbTextCompare)
Any other suggestions? I would appreciate it.
Also, in this case, I don't think the semi colon (;) is necessary.
Mark
-
Duh, why didn't I think of this initially?
It works perfect now
Here is the answer:
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
We missed the obvious; Currpaths is the variable set to hold the current support paths.
CurrPaths = Preferences.Files.SupportPath
In which case, when using the replace function, we want to simply replace currpaths (which is holding the current paths) to currpaths = currpaths - deletepaths
End result:
Preferences.Files.SupportPath = CurrPaths (currpaths = currpaths - deletepaths)
I hope this makes sense?
Anyhow, it is working as planned
Mark
-
Well done.
-
Well, thank you :-)