2015-10-27 156 views
1

我保存正确的Visual Basic代码,但我需要它来加载一个特定的行并将其设置为一个整数,这里是我的代码有保存Visual Basic中读取特定行

Dim Red as Integer 
    Dim b as String 
    b = "" 
      Dim objReader As New System.IO.StreamReader(Path) 
      Do While objReader.Peek() >= -1 
       b = File.ReadLines(Path).Skip(1).Take(1).First() 

      Loop 
      objReader.Close() 
    val(b) 
      Red = b 
      TextBox2.Text = Red 

当我使用这,它冻结了,我不得不关闭它使用任务管理器,有没有另一种方式来格式化,使其正常工作?

+0

那是VBA? 看起来更像VB.NET – MatthewD

+0

我要回滚你的编辑。如果您想为未来的人发布问题解决方案,请在下面的空白处为此提供实际答案。在这里回答你自己的问题是可以接受的 - 请参阅[我可以回答我自己的问题?](http://stackoverflow.com/self-answer)了解更多信息。 –

回答

0

我发现通过删除代码将根据需要读取该特定行的do循环,而不会使系统崩溃,跳过它跳过的行数。

Dim Red as Integer 
    Dim b as String 
    b = "" 
      Dim objReader As New System.IO.StreamReader(Path) 
       b = File.ReadLines(Path).Skip(1).Take(1).First() 
      objReader.Close() 
    val(b) 
      Red = b 
      TextBox2.Text = Red 
0
dim myfilepath as string = "c:\myfilepath" 
    If My.Computer.FileSystem.FileExists(myfilepath) Then 
    dim mytext s string() = split(My.Computer.FileSystem.ReadAllText(myfilepath),vbCrLf) 
    dim red as integer 
    dim linecounter as integer = 0 
    dim specificline as integer = "e.g." 0 
    For linecounter 0 to ubound(mytext) 
    if linecounter = specifline 
    red = mytext(x) 
    end if 
    next 

    end if