Hi guys I want to used a dialog box in vb.net to open a txt file, which contains single line of a few character like TFTFFTFT, and store it into array.

Then I will open another txt file and compare it content with the first txt file..
How can I go ahead with that. Thanks

Dani AI

Generated

Hi — good question. As suggested, please post any code you tried if you want targeted fixes. As asked, confirm you have VB.NET/Visual Studio and are building a WinForms or Console app (OpenFileDialog is easiest in WinForms). The basic flow is: let the user pick the first file, read its single line into a string, convert that string to a char array, then repeat for the second file and compare. A few gotchas: trim newlines, watch for spaces between characters, and consider case or encoding differences.

Here is a minimal VB.NET WinForms example you can adapt (place inside a button click handler):

' Example: put this in a Button_Click on a WinForms form
Dim firstText As String = ""
Dim secondText As String = ""

Using dlg As New OpenFileDialog()
    dlg.Filter = "Text Files|*.txt|All Files|*.*"
    If dlg.ShowDialog() = DialogResult.OK Then
        firstText = System.IO.File.ReadAllText(dlg.FileName).Trim()
    Else
        Return
    End If
End Using

Using dlg2 As New OpenFileDialog()
    dlg2.Filter = "Text Files|*.txt|All Files|*.*"
    If dlg2.ShowDialog() = DialogResult.OK Then
        secondText = System.IO.File.ReadAllText(dlg2.FileName).Trim()
    Else
        Return
    End If
End Using

Dim arr1() As Char = firstText.ToCharArray()
Dim arr2() As Char = secondText.ToCharArray()
' Compare with string equality or loop to find per-position differences
If firstText = secondText Then
    MessageBox.Show("Files match exactly.")
Else
    ' show mismatches or count differences...
End If

Quick tips: use Trim() to remove CR/LF, use Replace(" ", "") if your file has spaces between letters, or .ToUpperInvariant() for case-insensitive compare. Wrap file reads in Try/Catch to handle IO errors. Post the code you have and a sample pair of input lines if you want help finding why your comparison is not behaving as expected.

Recommended Answers

All 2 Replies

Show your work so far along with why you think it doesn't work so all can see and comment.
If you need to outsource this work, look to sites like Upwork and others.

commented: I seriously doubt there's anything to share apart from the text of the assignment... +16

Please explain what you mean by providing you with advice. Do you have VB.NET installed on your computer? Did you rprofessor show you how to use dialog boxes? Did you learn about opening txt files? What part of the assignment has you stumped?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.