Author Topic: Delete Un needed Support Paths  (Read 1037 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
Delete Un needed Support Paths
« 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

Code: [Select]
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
« Last Edit: June 10, 2007, 04:15:51 PM by Mark Thomas »

Bryco

  • Water Moccasin
  • Posts: 1850
Re: Delete Un needed Support Paths
« Reply #1 on: June 10, 2007, 01:30:31 PM »
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)

ML

  • Guest
Re: Delete Un needed Support Paths
« Reply #2 on: June 11, 2007, 09:30:09 AM »


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:

Code: [Select]
NewPaths = Replace(CurrPaths &  ";" , DeletePath(dpcount), "", 1, vbTextCompare)

We will see

Thank you

Mark

ML

  • Guest
Re: Delete Un needed Support Paths
« Reply #3 on: June 11, 2007, 01:01:58 PM »

Bry,

Your suggestion did not work:

Code: [Select]
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

ML

  • Guest
Re: Delete Un needed Support Paths
« Reply #4 on: June 11, 2007, 01:29:48 PM »

Duh, why didn't I think of this initially?
It works perfect now

Here is the answer:

Code: [Select]
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.
Code: [Select]
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:
Code: [Select]
Preferences.Files.SupportPath = CurrPaths  (currpaths = currpaths - deletepaths)

I hope this makes sense?

Anyhow, it is working as planned

Mark

Bryco

  • Water Moccasin
  • Posts: 1850
Re: Delete Un needed Support Paths
« Reply #5 on: June 11, 2007, 08:58:31 PM »
Well done.

ML

  • Guest
Re: Delete Un needed Support Paths
« Reply #6 on: June 11, 2007, 10:41:10 PM »

Well, thank you  :-)