【问题标题】:how to read txt file.?如何读取txt文件。?
【发布时间】:2009-11-25 15:30:30
【问题描述】:

我正在使用 vb6 代码读取文本文件。我的要求是如果该行以 6 开头,那么我需要阅读该行,否则我必须离开该行并转到下一行。谁能帮我怎么做?

if ( start pos == 6)
{
    //do
}
else
{
    //do noting
} 

我在 vb6 中需要这个帮助。

提前致谢。

【问题讨论】:

    标签: vb6


    【解决方案1】:

    试试这个

    Const ForReading = 1 
    Const TristateUseDefault = -2 
    
    Set oFS = CreateObject("Scripting.FileSystemObject")
    Set oFile = oFS.GetFile("yourfile.txt")
    Set oStream = oFile.OpenAsTextStream(ForReading, TristateUseDefault) 
    Do While Not oStream.AtEndOfStream 
       sRecord=oStream.ReadLine 
       If Substring(sRecord, 1, 1) = "6" Then
          ' do
       Else
          ' do nothing
       End If
    Loop 
    oStream.Close 
    

    【讨论】:

      【解决方案2】:

      类似的东西

      Dim nFileNum As Integer, sNextLine As String
      nFileNum = FreeFile
      Open "C:\log.txt" For Input As nFileNum
      Do While Not EOF(nFileNum)
          Line Input #nFileNum, sNextLine
          If Mid(sNextLine, 1, 1) = "6" Then
               'here what you want
          End If
       Loop
       Close nFileNum
      

      【讨论】:

      • Line Input 逐行读取,每行都读,6开头什么都不做
      猜你喜欢
      • 2014-04-21
      • 1970-01-01
      • 1970-01-01
      • 2019-11-19
      • 2019-08-04
      • 2015-02-20
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多