没有实战过VB,但最近帮一个朋友写一个小程序,指定用VB编程,比较郁闷,从头学起,现遇到一问题,请高手解答,谢谢!
问题描述:使用Do While Not EOF(1)不能正确判断文件结尾,程序无法退出循环.
代码如下:
写文件代码:Open (Trim(Text1.Text)) For Output As #1
            
            strSqlTmp = "select * from XD order by F154, F1 desc"
            resForm20.Open strSqlTmp, cnn, adOpenKeyset, adLockOptimistic
            If resForm20.RecordCount > 0 Then
                For i = 1 To nXuandiao
                    strOutputLine = ""
                    Set ITM = ListView1.ListItems(i)
                    If ITM.Checked = True Then      
                        strOutputLine = "XD"
                        For j = 1 To 155
                            strOutputLine = strOutputLine & "$" & resForm20.Fields(j).Value
                        Next j
                        Print #1, strOutputLine & "$"
                    End If
                    resForm20.MoveNext
                Next i
            End If
        Close #1
读出代码:
         Open Text1.Text For Input As #2
        iCol = 0
        iNumber = 0
        Do While Not EOF(1)                    
            strTextLineInput = ""
           Line Input #2, strTextLineInput  
            
            ' 相关处理
         Loop

解决方案 »

  1.   

    open时指定的文件号为 #2, 则应该写成EOF(2)
      

  2.   


     Open   Text1.Text   For   Input   As   #2 
                    iCol   =   0 
                    iNumber   =   0 
                    Do   While   Not   EOF(2)                                         
                            strTextLineInput   =   "" 
                          Line   Input   #2,   strTextLineInput     
                            
                            '   相关处理 
                      Loop