Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a folder from my vb code??? please

Status
Not open for further replies.

rahmanjan

Programmer
Joined
Apr 13, 2003
Messages
180
Location
AU
hi all,

I have an applications that lists some folders in a list list view object. What i want is that if the user clicks in one of the entries it should open a folder the it is done in My Computer thing in windows.

So what i want to know is how can i open a path let is say C:\windows in a new folder from my vb code?

regards,

raman
 
Use a simple SHELL Command from VB.

In the itemClick event of your list control.. use this code

[tt]
Private Sub object_ItemClick(ByVal Item As ListItem)

'Declare Variables
Dim ExplorerPath as String

'Start Shell Command using explorerpath _
'variable and Item Clicked

SHELL ExplorerPath & Item

End Sub
[/tt]

Hope this helps.




[yinyang] ¥oshi [yinyang]

-------------------------
"There is No Spoon.."
-------------------------
 
Hi ,

It doesn't work for me.

Dim ExplorerPath As String
ExplorerPath = "c:\windows\explorer.exe"
Shell ExplorerPath & "c:\setuplog.txt"

I don't know why?
anything wrong?

regrds

raman
 
should there be a space before C:\... and by inferrence after the explorer.exe. The concatenated string won't have this and the command line needs it.

I am not near my own machine so can't prove anything but I would put money on it. eg.

Dim ExplorerPath As String
ExplorerPath = "c:\windows\explorer.exe"
Shell ExplorerPath & " c:\setuplog.txt"
^

d8^))
 
Try the quintessential ShellExecute:

I added a Dir List and a command button to a form (just for an example)....
[tt]
Private Declare Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1

Private Sub Dir1_Change()
Command1.Caption = "Open " & Dir1.Path & " in Explorer"
End Sub

Private Sub Command1_Click()
ShellExecute Me.hwnd, _
vbNullString, _
Dir1.Path, _
vbNullString, _
"C:\", _
SW_SHOWNORMAL
End Sub[/tt]


Real men don't use Interrupt 21h.
 
That would be my fault, I forgot the space.

The code should be as follows.

[tt]
Private Sub object_ItemClick(ByVal Item As ListItem)
'NB: Change object as necessary, this is object specific

'Declare Variables
Dim ExplorerPath as String

'Start Shell Command using explorerpath _
'variable and Item Clicked

'Note: item is automatic fom the user Click in the
Folder Control.

ExplorerPath = "c:\windows\explorer.exe"

SHELL ExplorerPath & " " & Item

End Sub
[/tt]

Sorry bout the hash up..


[yinyang] ¥oshi [yinyang]

-------------------------
"There is No Spoon.."
-------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top