|
-
Apr 17th, 2000, 01:40 AM
#1
Hey there,
really need some help here.
Does anyone knows how to use VB to Browse for directories and files, like the "Explorer" in Windows?
My purpose is to select a file from a certain directories then, send it to users, just like the ICQ thing.
Can anyone help me out?
-
Apr 17th, 2000, 02:33 AM
#2
transcendental analytic
Simply you could use filelistbox, dirlistbox and drivelistbox. You could also develope a treestyle app like explorer using the tree. Commondialogbox is another simple solution.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Apr 17th, 2000, 02:45 AM
#3
Junior Member
Here you go, this should work:
First add a "CommonDialog" Control to your form from the "Microsoft Common Dialog Control 6.0" component (I called it "dlgOpenFile" in the following code), and then use this code.
Code:
'Open file dialog box
dlgOpenFile.Filter = "Executables (*.exe)|*.exe|" & _
"Text Files (*.txt)|*.txt|" & _
"All Files (*.*)|*.*" 'Change to match the files you want
dlgOpenFile.DialogTitle = "Select a file" 'Window Title
dlgOpenFile.Flags = _
cdlOFNFileMustExist + _
cdlOFNHideReadOnly + _
cdlOFNLongNames + _
cdlOFNExplorer
dlgOpenFile.CancelError = True
On Error Resume Next
dlgOpenFile.ShowOpen 'Open File Dialog Window
If Err.Number = cdlCancel Then 'The user canceled
Exit Sub
ElseIf Err.Number <> 0 Then 'Unknown error
MsgBox "Error " & Format$(Err.Number) & _
" selecting file." & vbCrLf & _
Err.Description
Exit Sub
End If
This will return a full path & Filename (i.e. "C:\AFolder\AFile.ext")
Hope this helps!
JMik
-
Apr 17th, 2000, 01:50 PM
#4
Hyperactive Member
Paste this in the declarations section of a module:
Code:
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Private Const BIF_RETURNONLYFSDIRS = &H1
and drop this somewhere in the module:
Code:
Public Function DialogSelectFolder(hOwner As Long, psTitle As String) As String
Dim udtBrowseInfo As BROWSEINFO, sPath As String
With udtBrowseInfo
.hOwner = hOwner
.pidlRoot = 0&
.lpszTitle = psTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With
sPath = Space$(512)
If SHGetPathFromIDList(SHBrowseForFolder(udtBrowseInfo), sPath) Then
DialogSelectFolder = Left(sPath, InStr(sPath, vbNullChar) - 1)
Else
DialogSelectFolder = ""
End If
End Function
It returns the selected folder, or "" if cancel was pressed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|