在窗体上有commondialog1,text1 commond1三个控件,我想单击commond1时,打开一个*.txt文件,让它在text1里显示出来?
用代码怎么编写?
谢谢
VB高手进,帮我编写一段简单代码?万分感谢
答案:2 悬赏:60 手机版
解决时间 2021-05-05 15:35
- 提问者网友:山高云阔
- 2021-05-04 18:43
最佳答案
- 五星知识达人网友:独行浪子会拥风
- 2021-05-04 19:53
Private Sub Command1_Click()
Dim myfilename As String
Dim temptext As String
Dim s As String
CommonDialog1.FileName = ""
CommonDialog1.Filter = "文本文件(*.txt)|*.txt"
CommonDialog1.ShowOpen
myfilename = CommonDialog1.FileName
If Len(myfilename) Then
Open myfilename For Input As #1
Do While Not EOF(1)
Line Input #1, temptext
s = s + temptext + vbCrLf
Loop
Close #1
Text1.Text = s
End If
End Sub
Dim myfilename As String
Dim temptext As String
Dim s As String
CommonDialog1.FileName = ""
CommonDialog1.Filter = "文本文件(*.txt)|*.txt"
CommonDialog1.ShowOpen
myfilename = CommonDialog1.FileName
If Len(myfilename) Then
Open myfilename For Input As #1
Do While Not EOF(1)
Line Input #1, temptext
s = s + temptext + vbCrLf
Loop
Close #1
Text1.Text = s
End If
End Sub
全部回答
- 1楼网友:孤独的牧羊人
- 2021-05-04 21:07
Private Sub Command1_Click() Dim bb As String Open "F:\京城的\vb\新建文件夹\自己作的屏保\mi.txt" For Input As #1 Input #1, bb Close
Text1.Text = bb
End Sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯