Private Sub open_Click()
Dim line As String
Dim text As String
On Error Resume Next
CommonDialog2.CancelError = True
CommonDialog2.DialogTitle = "打开文件"
CommonDialog2.FileName = ""
CommonDialog2.Filter = "文本文件(*.txt)|*.txt"
CommonDialog2.Flags = cdlOFNCreatePrompt + cdlOFNHideReadOnly
CommonDialog2.ShowOpen
If Err = cdlCancel Then Exit Sub
TextBoxSave.text = cdltest.FileName
Open cdltest.FileName For Input As #1
Do While Not EOF(1)
Line Input #1, line$
text$ = text$ + line$ + Chr$(13) + Chr$(10)
Loop
Text1.text = text$
Close #1
End Sub

解决方案 »

  1.   

    下面的才是正确的:Private Sub open_Click()
        Dim line As String
        Dim text As String
        On Error Resume Next
        cdltest.CancelError = True
        cdltest.DialogTitle = "打开文件"
        cdltest.FileName = ""
        cdltest.Filter = "文本文件(*.txt)|*.txt"
        cdltest.Flags = cdlOFNCreatePrompt + cdlOFNHideReadOnly
        cdltest.ShowOpen
        If Err = cdlCancel Then Exit Sub
        TextBoxSave.text = cdltest.FileName
        Open cdltest.FileName For Input As #1
        Do While Not EOF(1)
           Line Input #1, line$
           text$ = text$ + line$ + Chr$(13) + Chr$(10)
        Loop
        Text1.text = text$
        Close #1
    End Sub
      

  2.   

    最好改为:Private Sub open_Click()
        Dim line As String
        Dim text As String
        On Error GoTo Z
        cdltest.CancelError = True
        cdltest.DialogTitle = "打开文件"
        cdltest.FileName = ""
        cdltest.Filter = "文本文件(*.txt)|*.txt"
        cdltest.Flags = cdlOFNCreatePrompt + cdlOFNHideReadOnly
        cdltest.ShowOpen
        If Err = cdlCancel Then Exit Sub
        TextBoxSave.text = cdltest.FileName
        Open cdltest.FileName For Input As #1
            Do While Not EOF(1)
               Line Input #1, line$
               text$ = text$ + line$ + Chr$(13) + Chr$(10)
            Loop
            Text1.text = text$
        Close #1
    Z:
    End Sub
      

  3.   

    Private Sub open_Click()
    Dim line As String
    Dim text As String
    On Error Resume Next
    CommonDialog2.CancelError = True
    CommonDialog2.DialogTitle = "打开文件"
    CommonDialog2.FileName = ""
    CommonDialog2.Filter = "文本文件(*.txt)|*.txt"
    CommonDialog2.Flags = cdlOFNCreatePrompt + cdlOFNHideReadOnly
    CommonDialog2.ShowOpen
    If Err = cdlCancel Then Exit Sub
    textboxsave.text = CommonDialog2.FileName
    Open CommonDialog2.FileName For Input As #1
    Do While Not EOF(1)
    Line Input #1, line$
    text$ = text$ + line$ + Chr$(13) + Chr$(10)
    Loop
    textboxsave.text = text$
    Close #1
    End Sub