p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

pro_vb thread: Making A Path Dos Compatible

Message #1 by brose@u... on Mon, 23 Apr 2001 16:15:04
Rather than do this manually, you can use the scripting library functions to
derive your path for you.  Set yourself a reference to the Microsoft
Scripting Runtime (scrrun.dll).  Dim and set a File object, and then call
it's .ShortPath property.  Here's a snippet of code to get you started:

' Set a reference to the Scripting Runtime & add the Common Dialog
' Drop a command button and a common dialog control on a form
' =====================================
Private Sub Command1_Click()
Dim fil As Scripting.File
Dim fso As Scripting.FileSystemObject

    Set fso = New Scripting.FileSystemObject
    Set fil = fso.GetFile(Me.CommonDialog1.FileName)
    MsgBox fil.ShortName
    MsgBox fil.ShortPath
End Sub
' =====================================



-----Original Message-----
From: brose@u... [mailto:brose@u...]
Sent: Monday, April 23, 2001 9:14 AM
To: professional vb
Subject: [pro_vb] Making A Path Dos Compatible

This may be a stupid question and not beling in the Pro list but the 
VB_Basic list doesn't seem like most the posts are answered. Sorry...if it 
is too simple. I am making a program that runs a DOS program along with 
all its paramaters, etc. I cna get it to work fine if the program is in 
the same directory but I want to be able to pick the directory. What I did 
was (and sorry my code is at home so I will just explain) take the 
File1.Path and copy it into an array stripping all the spaces and 
splitting it by each "\". Then it checks each piece of the array and if it 
is longer than 8 characters it takes the first six and then adds a "~1" to 
the end. I then create a string that pieces it all together adding a "\" 
after each piece. I know the logic is right but for some reason my code 
gives given type mismatch errors. Since my code is at home I can't post it 
but here is a quick try:

Dim Item, strTempRead, strPath, arrPath()

strTempRead = Replace(File1.Path, " ", "")
arrPath = Split (strTempRead, "\")
For each Item in arrPath ()
If Len(arrPath(Item)) > 8 then
arrPath(Item) = Left(arrPath(Item), 6)
arrPath(Item) = arrPath(Item) + "~1"
End If
strPath = arrPath(Item) + "\"

That is pretty close to the code. Thanks for the help. 

  Return to Index