Solved

having a problem getting the working directory from a text box

Posted on 2003-11-04
4
190 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now