Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

question with select file

5 views
Skip to first unread message

u1636...@spawnkill.ip-mobilphone.net

unread,
Apr 12, 2003, 11:40:53 PM4/12/03
to
Dim filename As String
filename = "c:\Text.txt";
MyFile(filename);

Need the filename be selected from file
dialog box by a user clicking on its
name instead of hardcoded as in above.
how?. shellexecute...??
RW

--
Sent by 3 from yahoo in field com
This is a spam protected message. Please answer with reference header.
Posted via http://www.usenet-replayer.com/cgi/content/new

Frits

unread,
Apr 13, 2003, 2:19:35 AM4/13/03
to
2 methods to do the job:

1) Common Dialog Control
Select in the Project/components menu Microsoft Common Dialog Control.
Put the control on your form and add this code

Private Sub Command1_Click()
Me.CommonDialog1.Action = 1
Text1.Text = CommonDialog1.FileName
End Sub

2) Common Dialog API

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Sub Form_Load()
Dim OFName As OPENFILENAME
OFName.lStructSize = Len(OFName)
'Set the parent window
OFName.hwndOwner = Me.hWnd
'Set the application's instance
OFName.hInstance = App.hInstance
'Select a filter
OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0)
+ "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
'create a buffer for the file
OFName.lpstrFile = Space$(254)
'set the maximum length of a returned file
OFName.nMaxFile = 255
'Create a buffer for the file title
OFName.lpstrFileTitle = Space$(254)
'Set the maximum length of a returned file title
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = "C:\"
'Set the title
OFName.lpstrTitle = "Open File - KPD-Team 1998"
'No flags
OFName.flags = 0

'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then
Text1.Text = OFName.lpstrFile
Else
Text1.Text = ""
End If
End Sub

Example found on www.mentalis.org/index2.shtml

"russel...@yahoo.com" <u1636...@spawnkill.ip-mobilphone.net> wrote in
message news:l.105020525...@65-45-152-62-sj-01.cvx.algx.net...

0 new messages