标题:如何在TEXT里显示打开的文本呢?
只看楼主
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
结帖率:84.62%
 问题点数:0 回复次数:3 
如何在TEXT里显示打开的文本呢?
我设置了驱动器控件、文件目录控件、和文件控件,
想通过点击硬盘里任意某个文本文件的文件名,可以直接将想把这文本文件打开显示到Text1里

如何在TEXT里显示打开的文本呢?

Private Sub File1_Click()
Dim SelectedFile As TextBox
SelectedFile = File1.Path & "\" & File1.FileName
Text1.Text = Text(SelectedFile)

End Sub

请代我修改下!谢谢!

有高手提供答案如下:
Private Sub File1_Click()
    Dim aStr As String
    Open File1.Path & "\" & File1.FileName For Input As #1
    While Not EOF(1)
        Line Input #1, aStr
        Text1.Text = Text1.Text + aStr + vbCrLf
    Wend
End Sub




但执行时出现:

执行时出现提示框:





实时错误“76”
路径未找到 !

昨天 16:53:42
搜索更多相关主题的帖子: TEXT 文本 
2006-05-12 23:20
leon2
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:731
专家分:0
注 册:2005-3-18
得分:0 
你的文件是不是在驱动器目录下的?如果是,这段代码就出错了。

应该判断目录位置:

Private Sub File1_Click()
Dim aStr As String
Dim strFile As String
strFile = File1.Path
If Len(File1.Path) <> 3 Then '不是根目录
strFile = strFile & "\"
End If
strFile = strFile & File1.FileName

Open strFile For Input As #1
While Not EOF(1)
Line Input #1, aStr
Text1.Text = Text1.Text + aStr + vbCrLf
Wend
End Sub

[此贴子已经被作者于2006-5-12 23:53:24编辑过]

2006-05-12 23:52
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 
打开字数比较少的文本还行,

但打开比较大的文本时就不行了!总是在来回不断摆动左右、上下控件条!似乎死机了!
2006-05-14 10:22
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 

而且不直接打开文本文件,粘贴文本里的文字字数显示是正确的!
但是打开文件直接在TEXT显示则显示不正确的文字字数数字!

这什么地方错误呢?

代码如下:

Private Sub Command4_Click()
Timer1.Enabled = False
Dim c As Single, d As Single, e As Single, f As Single, g As Single, h As Single, s As Single
Dim str2 As String
Dim T2 As Integer
Dim tx2 As Integer
T2 = 0

For tx2 = 0 To Len(Text3.Text)
Text3.SelStart = tx2
Text3.SelLength = 1
str2 = Text3.SelText
If str2 = "," Or str2 = "。" Or str2 = "!" Or str2 = "《" Or str2 = "》" Or str2 = "“" Or str2 = "”:" Or str2 = ";" Or str2 = "、" Or str2 = "?" Or str2 = "," Or str2 = "." Or str2 = "0" Or str2 = "1" Or str2 = "2" Or str2 = "3" Or str2 = "4" Or str2 = "5" Or str2 = "6" Or str2 = "7" Or str2 = "8" Or str2 = "9" Then T2 = T2 + 1
Next tx2
T2 = T2 / 2

If Text3.Text <> "" Then
Text6.Text = Len(Replace(Text3.Text, " ", "")) - T2

2006-05-14 11:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-63743-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.210836 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved