如:有text1、text2、text3......textA、cmd1、cmd2
我在text1中输入"abc"
1、点击cmd1,读取"abc.txt"文件,然后把第1行显示在text2、第2行显示在text3......第A-1行显示在textA。如果无"abc.txt"则提示无此文件。2、点击cmd2,建立"abc.txt",将text2写入第1行......textA写入第A-1行。如果已有"abc.txt"则提示已有此文件。

解决方案 »

  1.   

    text2、text3......textA用控件数据text(1)...text(n)来表示会方便很多
      

  2.   

    Option ExplicitPrivate Sub Command1_Click()
       Dim FileNo As Integer
       Dim TextLine As String
       Dim FSO As New FileSystemObject
       
       If FSO.FileExists(App.Path & "\" & Trim(Text1.Text) & ".txt") = False Then
          MsgBox "文件不存在"
          Exit Sub
       End If
       
       FileNo = FreeFile()
       Open App.Path & "\" & Trim(Text1.Text) & ".txt" For Input As FileNo
       
       Dim curLine As Integer
       Do While Not EOF(FileNo)
          curLine = curLine + 1
          If curLine <= 12 Then
             Line Input #FileNo, TextLine
             Text(curLine).Text = TextLine
          End If
       Loop
       
    End SubPrivate Sub Command2_Click()
       Dim FileNo As Integer
       Dim i As Integer
       
       FileNo = FreeFile()
       Open App.Path & "\" & Trim(Text1.Text) & ".txt" For Output As FileNo
       For i = 1 To 12
          Print #FileNo, "Line" & i
       Next
       Close FileNo
       MsgBox "OK"
    End Sub