-1

This Code

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    My.Computer.FileSystem.CopyFile(
        Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\logs\latest.log",
        Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\logs\latestc.log")

        Using reader As New StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\logs\latestc.log")
            While Not reader.EndOfStream
                Dim line As String = reader.ReadLine()
                If line.Contains("Setting user: ") Then
                    Dim lastpart As String = line.Substring(line.LastIndexOf(": ") + 1)
                    FlatAlertBox3.Text = lastpart
                    Exit While
                End If
            End While
        End Using
        My.Computer.FileSystem.DeleteFile(
            Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\logs\latestc.log")

    End Sub

I want to this name http://prntscr.com/omml8w in richtextbox1.text like up code , but its not work , its add only first name not all names ,i want all names add in richtextbox up code , how can i do this plzz help me ^_^

RobertBaron
  • 2,817
  • 1
  • 12
  • 19
  • First of all you are replacing the text in the text box, causing it to be overwritten each time. You need to _append_ the names. -- Possible duplicate of [How do I add text to a textbox? Not replace](https://stackoverflow.com/questions/39797892/how-do-i-add-text-to-a-textbox-not-replace) – Visual Vincent Jul 31 '19 at 18:42
  • In addition to that, also remove `Exit While` as that stops the loop after the first entry has been found (hence why you only get the first name). – Visual Vincent Jul 31 '19 at 18:43
  • Rather than calling `Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData` four times, call it once and assign to a string variable. Then use that vaiable with `Path.Combine()`. – Mary Jul 31 '19 at 21:39

2 Answers2

1

As suggested in the comments, you need to append lastpart to the contents of the text box, and remove the Exit While which forces exiting the loop on the first iteration.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
    My.Computer.FileSystem.CopyFile(
        appDataFolder & "\.minecraft\logs\latest.log",
        appDataFolder & "\.minecraft\logs\latestc.log")

    Using reader As New StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\logs\latestc.log")
        ' Set text box to empty string.
        FlatAlertBox3.Text = ""
        While Not reader.EndOfStream
            Dim line As String = reader.ReadLine()
            If line.Contains("Setting user: ") Then
                Dim lastpart As String = line.Substring(line.LastIndexOf(": ") + 1)
                ' Append to contents of text box.
                FlatAlertBox3.Text += lastpart
                'Exit While
            End If
        End While
    End Using
    My.Computer.FileSystem.DeleteFile(appDataFolder & "\.minecraft\logs\latestc.log")

End Sub
RobertBaron
  • 2,817
  • 1
  • 12
  • 19
1

Try this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim AppData As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
    Dim logs As String = Path.Combine(AppData, ".minecraft\logs")
    Dim templog As String = Path.Combine(logs, "latestc.log")

    File.Copy(Path.Combine(logs, "latest.log"), templog, True)

    Dim settings = File.ReadLines(templog).
        Where(Function(line) line.Contains("Setting user: "))

    FlatAlertBox3.Text = String.Join(vbCrLf, settings)

    File.Delete(templog)
End Sub

Make sure to use Imports System.IO at the top of the file. I might also add a Try/Finally to be sure the File.Delete() runs.

For fun, we can write this as a one-liner:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load   
    FlatAlertBox3.Text = String.Join(vbCrLf, File.ReadLines(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".minecraft\logs\latest.log")).Where(Function(line) line.Contains("Setting user: ")))  
End Sub

Though I'd never use unreadable code like that in production.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794