Question how to comparing textbox.text with text file


New member
Feb 3, 2022
Programming Experience
i want to make a program to compare the code/serial number, the code is entered into a txt file which will be displayed in textbox 1 and when the serial number is entered into textbox 2 it will automatically (realtime) adjust/match the serial number in textbox 1 (txt files) while displayed.

I have made it, but the contents of the txt file are displayed entirely in textbox 1. this my code

Sub readtxt()
        Dim rf As New IO.StreamReader("D:\PROJECT\latihan.txt")
        Dim r As String
        Do Until rf.EndOfStream
            r = rf.ReadLine

        TextBox1.Text = TextBox1.Text & r & vbCrLf

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If TextBox1.Text = TextBox2.Text Then

        MsgBox("Nomor Seri Sama", MsgBoxStyle.Information)
        MsgBox("Nommor Seri Berbeda", MsgBoxStyle.Critical)
    End If
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Call readtxt()
End Sub

this image program


txt file
What's the actual problem here that you need help with? If it's about displaying text from a file in a TextBox then that's got nothing to do with comparing anything. If it's about comparing Strings then that's got nothing to do with files or TextBoxes. It seems like your actual issue is that you can't display the contents of a multi-line text file in a TextBox. If that's the problem then that's what you should have said. In that case, you would need to start by setting the Multiline property to True. There's then no point reading the file line by line if you want all the text. Just call File.ReadAllText and assign the result to the Text property.

Latest posts