Author Topic: Delete and Add Support Paths  (Read 3424 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
Delete and Add Support Paths
« on: September 27, 2007, 03:32:42 PM »
Hi,
In the below example I am simply deleting and adding support paths as needed.
The problem I am having is that if I add a path (i.e. NewPath(0) = "C:\")
Then if I were to manually delete The new path in Options-Files, run the macro again,
and remove that path from the macro (i.e. NewPath(0) = "")

It will still write The new path, which in the above example would be C:\

The only thing I can think of is that there is a variable that is holding onto that path and I suspect it is Currpaths but I am not sure.

Can anyone help me figure this out ?

Thank you,

Mark

Code: [Select]
Sub DeleteAndAddFileSearchPaths()

'DeletePaths
Set WshNetwork = CreateObject("WScript.Network")
Username = WshNetwork.Username


Set Preferences = ThisDrawing.Application.Preferences

CurrPaths = Preferences.Files.SupportPath

On Error Resume Next
'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 5
 CurrPaths = Replace(CurrPaths, DeletePath(Dpcount), "", 1, vbTextCompare)
Next Dpcount

Preferences.Files.SupportPath = CurrPaths


'Add Paths
NewPath(0) = ""
NewPath(1) = ""
NewPath(2) = ""
NewPath(3) = ""
NewPath(4) = ""


For Pcount = 0 To 5
 'Paths you want to add
 If NewPath(Pcount) <> 0 Then
  Allpaths = Allpaths & ";" & CurrPaths & ";" & NewPath(Pcount)
 End If
Next Pcount

Preferences.Files.SupportPath = Allpaths

End Sub

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Delete and Add Support Paths
« Reply #1 on: September 27, 2007, 03:41:26 PM »
i dont know if this will help of not, but I use 1 string for the main paths I am looking for i.e. strMainPath="c:\PF\Autocad\fonts;c:\PF\Autocad\support;etc;etc;etc" and then add the paths I want at startup.  I also use Instr() to search the existing path to check to see if I need to add the additional paths.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Delete and Add Support Paths
« Reply #2 on: September 27, 2007, 03:55:17 PM »
strMainpath=Application.Preferences.Files.SupportPath
instr(1,Application.Preferences.Files.SupportPath ,"Data",vbTextCompare ) will return the position where it is found, so you can us an IF statement to determine if you need to add another path
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

ML

  • Guest
Re: Delete and Add Support Paths
« Reply #3 on: September 27, 2007, 04:03:51 PM »

Hey CM

I'm not sure what Instr() is but it sounds interesting.
In my case, I think if I could clear the newpaths variable after the new paths are written that would take care of it except you can not say = Nothing to a variable that is an array.

I'm not even sure I can use that methos on a String Variable???

So, how could I clear the newpath variable?

Do you think that would do it?

Thanks

Mark

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Delete and Add Support Paths
« Reply #4 on: September 27, 2007, 04:10:33 PM »
Newpath should clear when the app finishes or loses scope.  How many paths are you using, and is the array necessary?  The reason I ask, the last time I was working with arrays, I was having a similiar problem, and Keith told me I couldn't do what I wanted because arrays are limited.  I was redim'ing though, so it might be the same.  As to setting it to nothing, what about Newpath(0)=" "  ?

Edited Note the blank space in that setting
« Last Edit: September 27, 2007, 04:16:27 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Delete and Add Support Paths
« Reply #5 on: September 27, 2007, 04:11:05 PM »
or maybe Newpath=Null  ?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Delete and Add Support Paths
« Reply #6 on: September 27, 2007, 04:19:41 PM »
I'm not sure what Instr() is but it sounds interesting.
It simply returns the position of the string you searched for.  I looked for the word DATA in my supportpath, and the "D" was the 89th letter in the string.  So you use an
Code: [Select]
IF Not Instr(1,path,"STRyouARElookingFOR",vbtextcompare) > 0 then
 AddPath   
Else
 DoNothing
End If
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Delete and Add Support Paths
« Reply #7 on: September 27, 2007, 04:22:02 PM »
From help file
Quote
InStr Function
     

Returns a Variant (Long) specifying the position of the first occurrence of one string within another.

Syntax

InStr([start, ]string1, string2[, compare])

The InStr function syntax has these arguments:

Part Description
start Optional. Numeric expression that sets the starting position for each search. If omitted, search begins at the first character position. If start contains Null, an error occurs. The start argument is required if compare is specified.
string1 Required. String expression being searched.
string2 Required. String expression sought.
compare Optional. Specifies the type of string comparison. If compare is Null, an error occurs. If compare is omitted, the Option Compare setting determines the type of comparison. Specify a valid LCID (LocaleID) to use locale-specific rules in the comparison.
In case you didn't know, if you type in InStr, highlight it and hit F1, it will give you the page I am referencing.
« Last Edit: September 27, 2007, 04:24:26 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

ML

  • Guest
Re: Delete and Add Support Paths
« Reply #8 on: September 27, 2007, 05:11:17 PM »

Yes sir

That did it.
I decided to go ahead and just clear all variables that are writing and deleting paths

Code: [Select]
'Clear all Path Variables
CurrPaths = Null
DeletePath(0) = Null
NewPath(5) = Null
Allpaths = Null

It is a good programming habit to set your variables to nothing (for obj)
and Null (for String)

I usually don't but this was a prime example as to why it needs to be done "ESPECIALLY" if you are running the macro again and again without closing down the project. It must be that the variable is retaining the information (in memory) that was last written to it until you close the project or set it to null or nothing.

As far as the InStr Function, that is a good one, i will have to remember that and use it sometime :)

As far as arrays, i think they are very powerful and very efficient, I have never really had a problem with them except in one case where I was writing the paths directly to the registry.
In that VBScipt, I used 3 arrays and 2 out the 3 worked find.
For the 3rd one I just folded and ended up using
.regwrite
Path & ";" & Path & ";" Path & ";"
And it gets the job done.

Keith B. was explaining to me about splitting paths which was very interesting but I was not quite sure of the precise method of making that work, so I left good enough alone.

Have you heard of Split?

Thanks again,

Mark

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Delete and Add Support Paths
« Reply #9 on: September 27, 2007, 05:19:44 PM »
Yes, I have heard of it, but never have used it.  I dont know if its available in VBA.  I usually use Left() Mid() and Right() to split my strings
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

ML

  • Guest
Re: Delete and Add Support Paths
« Reply #10 on: September 27, 2007, 05:33:41 PM »

Ahhh, yes they are very useful but I think that Split is used in a different context.

I will get you a better definition of it

Keep in mind that if it can be used in VB or VBScripting, there is a good chance that you can use it in VBA

As you can see with my code, I use VBScripting code quite a bit.

Do you do much with VBScripting? Microsoft has a free user guide on their site in html.

If you got VBA, then VBScripting is real easy.

The great thing about script code is that you can do Windows (system) things from within the app :)

Like copying files from one location to another,
If fileexists
Writing to a text file, which is VERY cool

Just to name a few

Mark

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Delete and Add Support Paths
« Reply #11 on: September 28, 2007, 06:08:22 PM »
is this what you were referring to?
Quote
Split()
Returns a zero-based, one-dimensional array containing a specified number of substrings.
« Last Edit: September 28, 2007, 06:13:19 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

ML

  • Guest
Re: Delete and Add Support Paths
« Reply #12 on: September 28, 2007, 06:14:04 PM »

I'm sorry??????

Are you referring to the split command?

If so, I'm not sure, I have not really lookied into it but it does sound cool

You going to try it?

Oh, in case you didn't check it out, here is the vbscript user guide


http://msdn2.microsoft.com/en-us/library/sx7b3k7y.aspx


Mark