VB用API函数浏览打开TXT文本文件,并读取TXT文本文件里的内容换行显示在LIST1(0)里这个怎么修改,帮忙

PrivateDeclareFunctionGetOpenFileNameLib"comdlg32.dll"Alias"GetOpenFileNameA"(pOpenfi... 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
Dim ofn As OPENFILENAME
Dim rtn As String
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Me.hWnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = "Text Files" & vbNullChar & "*.txt"
ofn.lpstrFile = Space(254) '这里可以改一个默认的文件名
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space(254)
ofn.nMaxFileTitle = 255
'ofn.lpstrInitialDir = App.Path
ofn.lpstrTitle = "请选择文章"
ofn.flags = 6148
rtn = GetOpenFileName(ofn)
If rtn <> 0 Then
List9(0).AddItem ofn.lpstrFile
Else
List9(0).AddItem "按了取消键!"
End If
展开
 我来答
EET888
2013-08-27
知道答主
回答量:26
采纳率:0%
帮助的人:19.1万
展开全部
你的意思是吧txt里面的数据全部分行显示到LIST1(0)里面吗?

在里面增加一段代码:
Dim s() As String, a As String
Open ofn.lpstrFile For Binary As #1 '把打开的数据读取到A
a = String(LOF(1), " ")
Get #1, , a
Close #1
s = Split(a, vbCrLf) '转化为数组
For i = 0 To UBound(s)
List1(0).AddItem s(i) '全部写入到list(0)
Next

完整源码下载地址:http://www.hilaiba.cn/Software.asp?id=96
更多追问追答
追问
对,但是 ofn.lpstrFilter = "Text Files" & vbNullChar & "*.txt"这句怎么修改是打开它呢,我晕你的能浏览我的电脑吗?
追答

看我给你共享的源码,里面已经很清楚了!

效果图:

不会加我QQ:173106206

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式