4 vb6
这是我的代码(注意这是由朋友给出的):
Private Sub Browse_Click()
Dim textfile As String
textfile = Space(255)
GetFileNameFromBrowseW Me.hWnd, StrPtr(sSave), 255, StrPtr("c:\"),
StrPtr("txt"), StrPtr("Apps (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) +
"All files (*.*)" + Chr$(0) + "*.*" + Chr$(0)), StrPtr("Select File")
Text1 = Left$(textfile, lstrlen(textfile))
End Sub
Run Code Online (Sandbox Code Playgroud)
基本上后来我编辑了所选的文本文件,所以稍后我只是在我的函数中使用textfile来调用它.但是我得到了一条未找到的路径,所以我觉得我做错了什么.提前致谢.
编辑:我想要做的就是选择一个文本文件,然后再调用它并使用它.
正如shahkalpesh所提到的,您只需使用标准COM库即可访问此功能.
在VB6中,添加组件:
现在在表单上,从工具箱中添加新的Common Dialog控件
在代码中,您需要:
CommonDialog.Filter = "Apps (*.txt)|*.txt|All files (*.*)|*.*"
CommonDialog.DefaultExt = "txt"
CommonDialog.DialogTitle = "Select File"
CommonDialog.ShowOpen
'The FileName property gives you the variable you need to use
MsgBox CommonDialog.FileName
Run Code Online (Sandbox Code Playgroud)