阅读最后一行 - 1

时间:2014-03-14 08:33:35

标签: vb.net

我创建了一个简单的程序来从这里工作的不同用户读取我们的登录日志。该程序工作正常,但我希望能够滚动条目。

日志中的每一行都有这样的条目,行数不确定,因为它取决于用户登录的次数和次数:

ussername;siteserver;loginserver;hostname;ipaddress;;windowsversion;datetime

我能够获得最后一行并将其显示在与此子对话的对话框中:

Dim title As String = "LogViewer"
        Dim SearchName As String = SearchInput.Text
        SearchName = SearchName.ToUpper()

        If Not SearchLog(SearchName) Is Nothing Then
            If (InStr(SearchName, "PC") Or InStr(SearchName, "NB")) Then

                System.Diagnostics.Debug.WriteLine(SearchLog(SearchName))
                Dim lines As String() = File.ReadAllLines(SearchLog(SearchName))
                Dim firstLine As String = lines.First
                Dim lastLine As String = lines.Last

                Dim SplitString() As String = lastLine.Split(";")
                Dim msg As New DeviceLog(SplitString(0), SplitString(1), SplitString(2), SplitString(3), SplitString(4), SplitString(5))
                msg.ShowDialog()
            Else
                SearchName = SearchName.ToLower
                System.Diagnostics.Debug.WriteLine(SearchLog(SearchName))
                Dim lines As String() = File.ReadAllLines(SearchLog(SearchName))
                Dim firstLine As String = lines.First
                Dim lastLine As String = lines.Last

                Dim SplitString() As String = lastLine.Split(";")
                Dim Usermsg As New UserLog(SplitString(3), SplitString(0), SplitString(4), SplitString(6), SplitString(7))
                Usermsg.ShowDialog()
            End If

        Else
            Dim msg As String = "Cannot Find Host or Username."
            MsgBox(msg, , title)

        End If
    End Sub

有没有办法让我获得最后一行 - 1并让它以某种方式递增,并附加一个按钮。我该怎么做呢有什么建议吗?

1 个答案:

答案 0 :(得分:0)

  

有没有办法让我得到最后一行 - 1并让它以某种方式增加一个计数器

您可以使用Enumerable.ReverseEnumerable.Skip

Dim reverse = lines.Reverse()
For counter As Int32 = 0 To lines.Length - 1
    Dim line = reverse.Skip(counter).First()
Next

您可以使用Int32 - 属性Counter

代替该循环