D:\aa.txt有一些字符

345345364u
23657567rtre
34535327r
43564hfhfh
....
....
等等
点击Command1,读取aa.txt,重第一行开始,每次一行循环显示在text1里,该怎么写
如第一个显示345345364u,然后清空text1再显示23657567rtre,然后再清空显示34535327r,以此类推

解决方案 »

  1.   

    Private Sub Command1_Click()
        Dim a As String, i As Long, t As Single, y() As String
        Dim fileNO As Integer
        fileNO = FreeFile
        Open "D:\aa.txt" For Binary As #fileNO    a = StrConv(InputB(LOF(fileNO), #fileNO), vbUnicode)
        y = Split(a, vbCrLf)
        For i = 0 To UBound(y)
            t = Timer
            Do Until Timer > t + 0.5
                DoEvents
            Loop
            Text1.Text = y(i)
        Next
        Close #fileNO
    End Sub
      

  2.   

    open "c:\aa.txt" for input as #1
    while not eof(1)
    line input #1,istr
    text1=istr
    wend
      

  3.   

    嘿嘿 大家别搞错了啊 楼主是说 点一下command1 读一行
    这需要设置一个public变量或static变量i
    用来记录本次点击时第i次点击 需要读第i行。
      

  4.   

    Private Sub Command1_Click()
      Dim istr As String
      If Not EOF(1) Then
        Line Input #1, istr
        Text1 = istr
      Else
        Close #1
        MsgBox "文件已经读完"
      End IfEnd SubPrivate Sub Form_Load()
      Open "c:\a.txt" For Input As #1End Sub
      

  5.   

    load里打开,command里按行读取...
      

  6.   

    也可以在oad里一次读取,将每行数据分别写到数组sData()里,设一全局变量num,在command里直接读取数组即可if num< ubound(sData) then
       Text1 = sData(num)
       num=num+1
    else
      Close #1
      MsgBox "文件已经读完"
    end if
      

  7.   

    做好了,记得“test.txt”放在同VB工程同一目录,
    如果有需要QQ联系:594661148Option ExplicitDim strPath As String
    Dim strFilename As String
    Dim i As Integer
    Dim intfileNO As Integer
    Dim txtData() As StringDim intClick As Integer     '//点击次数Private Sub Command1_Click()
        
        If Not intClick > UBound(txtData()) - 1 Then
        
            Text1.Text = txtData(intClick)
            intClick = intClick + 1
            
        Else
            
            Dim strResponse As String
            
            strResponse = MsgBox("文件已经读完,确定重置吗?", vbYesNo + vbDefaultButton2, "提示")
            
            If strResponse = vbYes Then intClick = 0
        
        End IfEnd SubPrivate Sub Form_Load()    intClick = 0  '//点击次数置零
        
        strPath = App.Path    Dim fileNO As Integer
        fileNO = FreeFile
        Open strPath + "\test.txt" For Binary As #fileNO    strFilename = StrConv(InputB(LOF(fileNO), #fileNO), vbUnicode)
        txtData = Split(strFilename, vbCrLf)
        
        Close #fileNOEnd Sub
      

  8.   

    试过,可以用,采用FSO
    程序如下:
    Dim fso As FileSystemObject
    Dim ts As TextStream
    Dim s As String
    Dim time, num As Integer
    Private Sub Command1_Click()
    Text1.Text = ""
    Set fso = CreateObject("scripting.filesystemobject")
    Set ts = fso.OpenTextFile("D:\55.txt", ForReading, True, TristateUseDefault)
    For num = 0 To time
            If num > 0 Then
            ts.SkipLine
            End If
            If ts.AtEndOfStream Then
            ts.Close
            Set ts = fso.OpenTextFile("D:\55.txt", ForReading, True, TristateUseDefault)
            End If
    Next
    time = time + 1
    s = ts.ReadLine
    Text1.Text = s
    ts.Close
    End SubPrivate Sub Form_Load()
    time = 0
    num = 0
    End Sub
      

  9.   

    楼主这个帖还没结啊
    Private Declare Function SafeArrayGetDim Lib "oleaut32.dll" (ByRef saArray() As Any) As Long
    Dim sLine() As String
    Private Sub Command1_Click()
    Dim s As String, i As Integer
    Command1.Tag = Val(Command1.Tag) + 1
    If SafeArrayGetDim(sLine) <= 0 Then
        Open "c:\httpdownload.txt" For Input As #1
        Do While Not EOF(1)
            Line Input #1, s
            i = i + 1
            ReDim Preserve sLine(1 To i)
            sLine(i) = s
        Loop
    End If
    If Val(Command1.Tag) <= UBound(sLine) Then
        Debug.Print sLine(Val(Command1.Tag))
    Else
        MsgBox "文件已读完"
    End If
    End Sub