VB6.0中,如何实现读取TXT文件中的内容并在VB上显示出来?
创建AcitveX控件,在其中添加一个ListBox我需要实现,VB自动读取桌面上某TXT文件中的所有内容,并显示在ListBox中,怎么实现呢?(而这个TXT文件中的内...
创建AcitveX控件,在其中添加一个ListBox 我需要实现,VB自动读取桌面上某TXT文件中的所有内容,并显示在ListBox中,怎么实现呢?(而这个TXT文件中的内容是随时都可能变化的,每个人电脑桌面路径也有可能不同) 先谢谢各位大侠了
展开
展开全部
'这么点事儿创建AcitveX控件应该没太大意义,而且要写许多属性方法等,这里写不下,就给你个窗体的例子吧,希望能按字论赏
'通用声明
Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long
Const MAX_LEN = 200
Dim sTmp As String * MAX_LEN
Dim pidl As Long
Dim sp As String
'窗体加载事件
Private Sub Form_Load()
Dim strTxt$
SHGetSpecialFolderLocation 0, DESKTOP, pidl '参数DESKTOP就是获取用户桌面
SHGetPathFromIDList pidl, sTmp '获取实际路径
sp = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '赋给变量sp,方便调用
Open sp & "\1.txt" For Input Access Read As #1 '比如桌面上有1.txt
Do While Not EOF(1)
Line Input #1, strTxt
List1.AddItem strTxt
Loop
Close #1
End Sub
'通用声明
Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long
Const MAX_LEN = 200
Dim sTmp As String * MAX_LEN
Dim pidl As Long
Dim sp As String
'窗体加载事件
Private Sub Form_Load()
Dim strTxt$
SHGetSpecialFolderLocation 0, DESKTOP, pidl '参数DESKTOP就是获取用户桌面
SHGetPathFromIDList pidl, sTmp '获取实际路径
sp = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '赋给变量sp,方便调用
Open sp & "\1.txt" For Input Access Read As #1 '比如桌面上有1.txt
Do While Not EOF(1)
Line Input #1, strTxt
List1.AddItem strTxt
Loop
Close #1
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询