如果用vb的按钮来打开txt文件并导入文本怎么写?
PrivateSubCommand1_Click()Command1.filename=App.PathCommand1.Filter="文本文件(*.txt)|*.tx...
Private Sub Command1_Click()
Command1.filename = App.Path
Command1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|"
Command1.DialogTitle = "打开文件"
Command1.ShowOpen
Dim i As Integer
Open commanddialog1.filename For Input As #1
Do While Not EOF(1)
List1.Text = m
Close #1
End Sub
为什么说未找到方法或数据成员??? 展开
Command1.filename = App.Path
Command1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|"
Command1.DialogTitle = "打开文件"
Command1.ShowOpen
Dim i As Integer
Open commanddialog1.filename For Input As #1
Do While Not EOF(1)
List1.Text = m
Close #1
End Sub
为什么说未找到方法或数据成员??? 展开
2个回答
展开全部
Private Sub Command1_Click()
CommonDialog1.InitDir = App.Path
CommonDialog1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|"
CommonDialog1.DialogTitle = "打开文件"
CommonDialog1.ShowOpen
Dim i As Integer, m As String
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Line Input #1, m
List1.AddItem m
Loop
Close #1
End Sub
CommonDialog1.InitDir = App.Path
CommonDialog1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|"
CommonDialog1.DialogTitle = "打开文件"
CommonDialog1.ShowOpen
Dim i As Integer, m As String
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Line Input #1, m
List1.AddItem m
Loop
Close #1
End Sub
展开全部
Private Sub Command1_Click()
Dim i, arr
With CreateObject("UserAccounts.CommonDialog")
.Filter = "txt File|*.txt": .InitialDir = "d:\"
f = .ShowOpen
If f Then
List1.Clear
Open .filename For Input As #1
arr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbNewLine)
Close #1
For i = 0 To UBound(arr)
List1.AddItem arr(i)
Next
End If
End With
End Sub
Dim i, arr
With CreateObject("UserAccounts.CommonDialog")
.Filter = "txt File|*.txt": .InitialDir = "d:\"
f = .ShowOpen
If f Then
List1.Clear
Open .filename For Input As #1
arr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbNewLine)
Close #1
For i = 0 To UBound(arr)
List1.AddItem arr(i)
Next
End If
End With
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询