944,111 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
May 30th, 2006
0

FileOpen Dialog without using Common Dialog Control

Expand Post »
Good Morning guys,

Can someone please tell me how to insert a fileopen dialog in VB? What I want is when the user clicks on a button, the program takes them to a particular directory or folder, that way they will be able to select files on their own from that folder.

For some reason, I do not have the CommonDialog control which should be under "Additional Controls." Is there a way I can install the commondialog control into my system? Please let me know.

If there is a thread that already exist in this forum regarding opening the dialog box, please send it to me. Thank you very much for your anticiapted cooperation.

Ini
Similar Threads
INI
Reputation Points: 13
Solved Threads: 0
Light Poster
INI is offline Offline
39 posts
since May 2006
May 30th, 2006
0

Re: FileOpen Dialog without using Common Dialog Control

in a module:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ' /* Code Taken From: http://forums.devx.com/showthread.php?t=148627 */
  2. Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
  3.  
  4. Public Type OPENFILENAME
  5. lStructSize As Long
  6. hwndOwner As Long
  7. hInstance As Long
  8. lpstrFilter As String
  9. lpstrCustomFilter As String
  10. nMaxCustFilter As Long
  11. nFilterIndex As Long
  12. lpstrFile As String
  13. nMaxFile As Long
  14. lpstrFileTitle As String
  15. nMaxFileTitle As Long
  16. lpstrInitialDir As String
  17. lpstrTitle As String
  18. flags As Long
  19. nFileOffset As Integer
  20. nFileExtension As Integer
  21. lpstrDefExt As String
  22. lCustData As Long
  23. lpfnHook As Long
  24. lpTemplateName As String
  25. End Type
  26.  
  27. public Function SelectFileOpenDialog()
  28. Dim strTemp, strTemp1, pathStr As String
  29. Dim i, n, j As Long
  30. Dim OpenFile As OPENFILENAME
  31. Dim lReturn As Long
  32. Dim sFilter As String
  33. Dim Fname As String
  34.  
  35. OpenFile.lStructSize = Len(OpenFile)
  36. sFilter = "Text Files (*.txt)" & Chr(0) & "*.TXT" & Chr(0)
  37. OpenFile.lpstrFilter = sFilter
  38. OpenFile.nFilterIndex = 1
  39. OpenFile.lpstrFile = String(257, 0)
  40. OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
  41. OpenFile.lpstrFileTitle = OpenFile.lpstrFile
  42. OpenFile.nMaxFileTitle = OpenFile.nMaxFile
  43. OpenFile.lpstrInitialDir = "C:\"
  44. OpenFile.lpstrTitle = "Select File"
  45. OpenFile.flags = 0
  46.  
  47. lReturn = GetOpenFileName(OpenFile)
  48.  
  49. If lReturn = 0 Then
  50. MsgBox "You didn't select any file"
  51. Else
  52. 'MsgBox "The user Chose " & Trim(OpenFile.lpstrFile)
  53.  
  54. Fname = Trim$(OpenFile.lpstrFileTitle) ' copy the filename to "Fname"
  55.  
  56. n = FileLen(OpenFile.lpstrFile) 'length of the file
  57.  
  58. End Function

Then call it with a form like:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Form_Load()
  2. SelectFileOpenDialog
  3. End Sub

It's easy enough to modify anything you need to change (such as the initdir) openfile UDT
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 30th, 2006
0

Re: FileOpen Dialog without using Common Dialog Control

Thank you for the info; when I tried it, it opened the dialog box of teh particular folder, but when I clicked on the file to open nothin happened.

Do you know how I can install a common dialog control into my system? Because if I had that, my program will be much easier. Also the code you gave me is to long, I appreciate it very much but do you have access to a shorter code?

Ini
INI
Reputation Points: 13
Solved Threads: 0
Light Poster
INI is offline Offline
39 posts
since May 2006
May 30th, 2006
0

Re: FileOpen Dialog without using Common Dialog Control

not without using the commondialog control..... you can download the .ocx from just about anywhere..... once you have it downloaded, place it in the windows\system32 folder, and click start, run, regsvr32 c:\windows\system32\comdlg32.ocx, and hit enter..... then you should have it on the system. I personally suggest the API method over the ocx, though, since the api method is standalone, and doesn't require such dependancies.... but whatever boats your float.

http://www.ascentive.com/support/new...e=COMDLG32.OCX
Attached Files
File Type: zip commondialog.zip (1.8 KB, 395 views)
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 30th, 2006
0

Re: FileOpen Dialog without using Common Dialog Control

Thank you very much.

Ini
INI
Reputation Points: 13
Solved Threads: 0
Light Poster
INI is offline Offline
39 posts
since May 2006
May 30th, 2006
0

Re: FileOpen Dialog without using Common Dialog Control

This is what I have; do you think you could figure a way I could specify which directory I want?

Thanks.

Ini

___________________________________________________

Dim UF As Variant
UF = Application.GetOpenFileName(FileFilter:="Excel workbooks(*.xls), *.xls", Title:="Excel Files")
If UF = False Then
Exit Sub
Else
If UF <> "" Then
Workbooks.Open Filename:=UF
End If
End If
INI
Reputation Points: 13
Solved Threads: 0
Light Poster
INI is offline Offline
39 posts
since May 2006
May 30th, 2006
0

Re: FileOpen Dialog without using Common Dialog Control

You would be better off calling the premade function SelectFileOpenDialog, as is in the attachment, but your call getopenfilename should be passed a variable of the OPENFILENAME UDT. So, maybe you want to make one of those, and set all it's elements before calling the API.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 30th, 2006
0

Re: FileOpen Dialog without using Common Dialog Control

Please could you help me write code? Thanks.

Also I have another one that works using FileDialog, as the top code, it opens the dialog but will not open the file. please make the right corrections for me (code).

Dim FD As FileDialog
'Create a FileDialog object as a File Picker dialog box.
Set FD = Application.FileDialog(msoFileDialogFilePicker)

FD.Title = "Choose file to open"
FD.InitialFileName = "H:\"
FD.Show




Ini
INI
Reputation Points: 13
Solved Threads: 0
Light Poster
INI is offline Offline
39 posts
since May 2006
May 30th, 2006
0

Re: FileOpen Dialog without using Common Dialog Control

I dunno, I've never used the FileDialog object. It's not a standard part of VB6, and I dunno where you got it. you should be able to call a property that gets set when the file is selected, maybe something like FD.Filename, but since I don't use it, I wouldn't know....

In the first example, it looks like you are trying to open the file in excel.... which would be something more like:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. dim objExcel
  2. dim objworkbook
  3. Set objExcel = CreateObject("Excel.Application")
  4. Set objWorkbook = objExcel.Workbooks.Open(file_from_dialogbox_here)
  5. objExcel.visible = true
  6.  
  7. set objExcel = nothing
  8. set objWorkbook = nothing
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 30th, 2006
0

Re: FileOpen Dialog without using Common Dialog Control

I tried what you said about registering my comdlg32.ocs; it said successful, but when I tried drawing the dialog box on the form I get this error " This control could not be created because it is not properly registered." What can I do?

Ini
INI
Reputation Points: 13
Solved Threads: 0
Light Poster
INI is offline Offline
39 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: tabledef in ado
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: changing menu control





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC