Solved

having a problem getting the working directory from a text box

Posted on 2003-11-04
4
193 Views
Last Modified: 2010-05-03
This is the code I have in my app:-

Dim sFile As String
Dim sCommand As String
Dim sWorkDir As String

sFile = (Text1)
sCommand = vbNullString
sWorkDir = (Text1)
ShellExecute hwnd, "open", sFile, sCommand, sWorkDir, 1

i need the sWorkDir to get the directory of text1, not the whole filename as it is currently doing, is there a simple way to do this?
0
Comment
Question by:DamianVB
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
aelatik earned 125 total points
ID: 9679925
Dim sFile As String
Dim sCommand As String
Dim sWorkDir As String

sFile = Right(Text1, InStr(1, StrReverse(Text1), "\", vbTextCompare) - 1)
sCommand = vbNullString
sWorkDir = Mid(Text1, 1, Len(Text1) - InStr(1, StrReverse(Text1), "\", vbTextCompare) + 1)
ShellExecute hwnd, "open", sFile, sCommand, sWorkDir, 1
0
 
LVL 14

Expert Comment

by:aelatik
ID: 9679940
First try this to see if the positions are correct, if not just play with the + 1 and - 1

MsgBox Mid(Text1, 1, Len(Text1) - InStr(1, StrReverse(Text1), "\", vbTextCompare) + 1)
MsgBox Right(Text1, InStr(1, StrReverse(Text1), "\", vbTextCompare) - 1)
0
 
LVL 10

Expert Comment

by:MrClyfar
ID: 9679962
Hi there.

Not sure if there is an API to do this already, doubt it, but you could try the following code:

Private Function GetDirectory(sFilename As String) As String

Dim sTmpFilename As String
Dim iSlashPos    As Integer

sTmpFilename = StrReverse(sFilename)

iSlashPos = InStr(1, sTmpFilename, "\")

GetDirectory = Left$(sFilename, Len(sFilename) - (iSlashPos))
End Function

Example

Debug.Print GetDirectory("C:\Temp\Files\File.txt")

will print "C:\Temp\Files"

Hope this helps.
Jas.
0
 

Author Comment

by:DamianVB
ID: 9679992
I just tried that code aelatik and it now works perfectly, thanks very much :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question