要求是这样的:
在resolution目录中有一些文本文件,用户在文本框2中输入文件名,就能直接打开resolution目录中对应的文件在文本框1中进行查看。如果文件不存在,则跳出一个窗口提示文件不存在。从别处参考了一段,但是时间紧,来不及研究了,请大家帮忙!Private Sub Command1_Click()
Dim A, S, L As StringDim FreeNum As Integer
FreeNum = FreeFile 
L = "resolution\" + Text2.Text
Open L For Input As #FreeNumDo Until EOF(FreeNum) 
Line Input #FreeNum, A
S = S + vbNewLine + A 
If A = 1 And Not EOF(FreeNum) Then '感觉这里的A = 1有问题
Line Input #FreeNum, A 
Exit Do 
End If
Loop
Close FreeNumText1.Text = S
End Sub谢谢大家了。

解决方案 »

  1.   

    用RichTextBox,一个方法就加载完文件了。RichTextBox1.LoadFile  路径文件名
      

  2.   

    Private Sub Command1_Click()
        Dim L As String
        
        Dim FreeNum As Integer
        FreeNum = FreeFile
        L = "resolution\" + Text2.Text
        If Dir(L) = "" Then
            MsgBox "文件不存在!"
            Exit Sub
        End If
        
        Open L For Input As #FreeNum
            Text1.Text = StrConv(InputB$(LOF(FreeNum), FreeNum), vbUnicode)
        Close #FreeNum
    End Sub
      

  3.   

    记得把TextBox的MultiLine属性设置为True
      

  4.   

    Private Sub Command1_Click()
    Dim temp As String, s As String
    temp = "resolution\" & Text2.Text
    If Len(Dir(temp)) = 0 Then
    Err.Raise 53
    Else
    Open temp For Input As #1
    s = StrConv(Input(LOF(1), 1), vbUnicode)
    Close #1
    Text1.Text = s
    End If
    End Sub