在C盘下有个TEST.TXT,里面有两行数据,现在用VB将这两行分别读出来,并且赋给TEXT1,TEXT2
..................................马上结账.

解决方案 »

  1.   

    open "c:\test.txt" for input as #1
         do while not eof(1)
            line input #1,text1.text
            line input #1,text2.text
         loop
    close #1
      

  2.   

    '引用microsoft script runtime
    Private Function ReadFileLine(cfile As String, cLine As Integer) As String
        Dim I As Integer
        Dim fsoTest As New FileSystemObject, file1 As File, ts As TextStream
        Set file1 = fsoTest.GetFile(cfile)
        Set ts = file1.OpenAsTextStream(ForReading)
        I = 1
        Do While Not ts.AtEndOfStream
            If I <> cLine Then
                ts.ReadLine
            Else
                ReadFileLine = ts.ReadLine
            End If
            I = I + 1
        Loop
        MsgBox "总行数" & I
        Set ts = NothingEnd FunctionPrivate Sub Form_Load()
       MsgBox "读取行的内容为:" & (ReadFileLine("c:\test.txt", 2))   MsgBox "读取行的内容为:" & (ReadFileLine("c:\test.txt", 3))End Sub